I'm not understanding something about binding. I have a DataTemplate
for type Object which is working, but in there I want to make another ListBox
and set the data to that of one of the properties of an Object. I've been using Snoop to look at the data context and the data context of the ListBox
in the Object DataTemplate
is an Object, but there is an error with the ItemsSource
and I don't know why. I'm doing ItemsSource={Binding componentList, Mode=TwoWay}
and an Object has a componentList and componentList is an ObservableList
. What am I missing?
Here's my XAML code:
<Window.Resources>
<DataTemplate DataType="{x:Type properties:Component}">
<StackPanel>
<TextBlock Text="TEST COMPONENT" />
<ListBox DataContext="{Binding propertyList}" ItemsSource="{Binding propertyList}" />
</StackPanel>
</DataTemplate>
<DataTemplate DataType="{x:Type properties:Object}">
<StackPanel>
<TextBlock Text="TEST OBJECT" />
<ListBox ItemsSource="{Binding componentList, Mode=TwoWay}" />
</StackPanel>
</DataTemplate>
</Window.Resources>
And my C# code:
public class Component
{
public string name;
public ObservableCollection<IProperty> propertyList;
}
public class Object
{
public UnsignedProperty objectID;
public ObservableCollection<Component> componentList;
}
I make a ListBox
in code and set it's ItemsSource
to a list of Objects and that's seeing my Object DataTemplate
, but that's where it stops
ListBox properties = new ListBox();
ObservableCollection<Properties.Object> t = new ObservableCollection<Properties.Object>();
t.Add(selectedObject); //potentially more objects
properties.ItemsSource = t;
PropertyPane.Content = properties;
any help would be much appreciated. Thanks!