【发布时间】:2013-09-06 04:41:58
【问题描述】:
有人帮我创建一个复选框列表吗?..我在 wpf 和 mvvm 模式中需要它,绑定...只有在选中标题复选框时才应启用项目复选框..
我的代码是
我的 xaml 是
<ListBox ItemsSource="{Binding CheckBoxListItemCollection}">
<ListBox.ItemTemplate>
<HierarchicalDataTemplate DataType="{x:Type CheckBox}" ItemsSource="{Binding CheckBoxSubItems}">
<ListBox ItemsSource="{Binding ItemHeader}"></ListBox>
</HierarchicalDataTemplate>
</ListBox.ItemTemplate>
</ListBox>
我有课
public class CheckBoxListItems
{
public CheckBoxListItems()
{
CheckBoxSubItems = new ObservableCollection<CheckBox>();
ItemHeader = new ObservableCollection<CheckBox>();
}
public ObservableCollection<CheckBox> ItemHeader { get; set; }
public ObservableCollection<CheckBox> CheckBoxSubItems { get; set; }
}
我的 Viewmodel 有
private List<CheckBoxListItems> _checkBoxListItemCollection;
CheckBoxListItemCollection = new List<CheckBoxListItems>();
public List<CheckBoxListItems> CheckBoxListItemCollection
{
get
{ return _checkBoxListItemCollection; }
set
{
if (_checkBoxListItemCollection != value)
{
_checkBoxListItemCollection = value;
OnPropertyChanged(new PropertyChangedEventArgs("CheckBoxItems"));
}
}
}
我试过了
<TreeView ItemsSource="{Binding CheckBoxListItemCollection}" >
<DataTemplate >
<ListBox ItemsSource="{Binding CheckBoxSubItems}"></ListBox>
</DataTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding CheckBoxSubItems}">
<ListBox ItemsSource="{Binding ItemHeader}"></ListBox>
</HierarchicalDataTemplate>
</TreeView>
【问题讨论】: