Do any one help me in creating a checkbox list so?..I need it in wpf and in mvvm pattern,binding...Item checkbox should be enabled only when header checkbox is ticked..
I have the code as
My xaml is
<ListBox ItemsSource="{Binding CheckBoxListItemCollection}">
<ListBox.ItemTemplate>
<HierarchicalDataTemplate DataType="{x:Type CheckBox}" ItemsSource="{Binding CheckBoxSubItems}">
<ListBox ItemsSource="{Binding ItemHeader}"></ListBox>
</HierarchicalDataTemplate>
</ListBox.ItemTemplate>
</ListBox>
I have a class
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; }
}
My Viewmodel has
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"));
}
}
}
I have tried as
<TreeView ItemsSource="{Binding CheckBoxListItemCollection}" >
<DataTemplate >
<ListBox ItemsSource="{Binding CheckBoxSubItems}"></ListBox>
</DataTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding CheckBoxSubItems}">
<ListBox ItemsSource="{Binding ItemHeader}"></ListBox>
</HierarchicalDataTemplate>
</TreeView>