1

I have the following data model, which is a collection within a collection:

var details1 = new ObservableCollection<Class2>();
details1.Add(new Class2() { Title = "text1" });
details1.Add(new Class2() { Title = "text2" });

var details2 = new ObservableCollection<Class2>();
details2.Add(new Class2() { Title = "text3" });
details2.Add(new Class2() { Title = "text4" });

var Items = new ObservableCollection<Class1>();
items.Add(new Class1() { IsActive = false, Details = details1 });
items.Add(new Class1() { IsActive = true, Details = details2 });

Next, I have a ListBox with ItemsSource bound to Items. The DataTemplate of this list contains another ListBox and its ItemsSource is bound to Details.

In short, my XAML is displaying a list of items and each item is showing a list of item details.

The problem that I have is that I do not know how to bind the value of IsActive property, which belongs to Class1, inside of DataTemplate of the inner ListBox which is associated with Class2 items.

I played with

"{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBoxItem}}, Path=DataContext.IsActive}"

but that doesn't work.

4

0 回答 0