Wpf 如何将对象数据从Combobox绑定到ListBox
这是自定义对象:Wpf 如何将对象数据从Combobox绑定到ListBox,wpf,data-binding,listbox,Wpf,Data Binding,Listbox,这是自定义对象: public class FileItem { public string Name { get; set; } public string Path { get; set; } } 收藏: public ObservableCollection<FileItem> collection { get; set; } 列表框: <ComboBox Name="cbCollection" ItemsSource="{Bindi
public class FileItem
{
public string Name { get; set; }
public string Path { get; set; }
}
收藏
:
public ObservableCollection<FileItem> collection { get; set; }
列表框
:
<ComboBox
Name="cbCollection"
ItemsSource="{Binding interfaces}"/>
<ListBox
Name="lbCollection "
ItemsSource="{Binding collection}">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
因此,我的组合框
中填充了我的对象
集合,我想在我的列表框
中查看它的所有属性
目前:
名称
组合框中的所有对象,而不仅仅是选定的对象
如果希望看到的不仅仅是name属性,那么需要扩展数据模板以包含其他属性 如果要查看所选项目的属性,则应绑定到组合框的
SelectedItem
属性。实际上,我不认为您需要一个列表框
,因为只有一个选定项
这应该让你开始:
<ContentControl Content="{Binding ElementName=cbCollection, Path=SelectedItem}">
<ContentControl.Resources>
<DataTemplate DataType="{x:Type local:FileItem}">
<TextBlock Text="{Binding Name}"/>
</DataTemplate>
</ContentControl.Resources>
</ContentControl>
我需要将此ContentControl放在哪里?用它替换您的列表框。错误5的值不能为空。参数名称:数据类型和错误6添加到IDictionary的所有对象都必须具有Key属性或与之关联的其他某种类型的键。仍然错误:在我的命名空间中找不到我的对象memeber(名称)