我对绑定不了解。我有一个DataTemplate正在工作的for类型的对象,但在这里我想做一个ListBox并将类型设置为对象属性之一的数据。我一直在使用Snoop来查看数据上下文,ListBox而Object中的数据上下文DataTemplate是Object,但是出现了错误,ItemsSource我不知道为什么。我在做ItemsSource={Binding componentList, Mode=TwoWay}一个对象有一个componentList和componentList是一个ObservableList。我想念什么?
这是我的XAML代码:
<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>
Run Code Online (Sandbox Code Playgroud)
和我的C#代码:
public class Component
{
public string name;
public ObservableCollection<IProperty> propertyList;
}
public class Object
{
public UnsignedProperty objectID;
public ObservableCollection<Component> componentList;
}
Run Code Online (Sandbox Code Playgroud)
我ListBox编写了一个in代码并将其设置ItemsSource为Objects列表,并看到了我的Object DataTemplate …