【问题标题】:Checkbox binding in wpfwpf中的复选框绑定
【发布时间】: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>

【问题讨论】:

标签: wpf binding checkbox


【解决方案1】:

如果我对您的理解正确,那么我相信您可以在 CodeProject 网站上的Working with Checkboxes in the WPF TreeView 文章中找到您的答案。

【讨论】:

    猜你喜欢
    • 2010-10-26
    • 2020-06-27
    • 1970-01-01
    • 2014-08-23
    • 1970-01-01
    • 1970-01-01
    • 2018-06-08
    • 1970-01-01
    • 2015-08-06
    相关资源
    最近更新 更多