0

Chekbox i want in following manner

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>
4

1 回答 1

0

如果我对您的理解正确,那么我相信您可以在 CodeProject 网站上的 WPF TreeView文章中的使用复选框中找到您的答案。

于 2013-09-06T09:00:02.107 回答