Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf 在多级树视图上使用ItemsControl_Wpf_Silverlight_Binding_Treeview_Itemscontrol - Fatal编程技术网

Wpf 在多级树视图上使用ItemsControl

Wpf 在多级树视图上使用ItemsControl,wpf,silverlight,binding,treeview,itemscontrol,Wpf,Silverlight,Binding,Treeview,Itemscontrol,我的同事威胁说今天要把我放在DailyWF上,因为我写的财产用于构建一个带有ItemsControl的三层树视图 我给你留下脚印: ObservableCollection<KeyValuePair<string, ObservableCollection<KeyValuePair<string, ObservableCollection<MyType>>>>>; observedcollection; 我的目标是创建一个Items

我的同事威胁说今天要把我放在DailyWF上,因为我写的财产用于构建一个带有ItemsControl的三层树视图

我给你留下脚印:

ObservableCollection<KeyValuePair<string, ObservableCollection<KeyValuePair<string, ObservableCollection<MyType>>>>>;
observedcollection;
我的目标是创建一个ItemsControl,该控件将使用键作为标题,并将值作为3个级别的ItemsSource:

<Style x:Key="filterTreeStyle" TargetType="ItemsControl">
        <Setter Property="ItemTemplate">
            <Setter.Value>
                <DataTemplate>
                    <controls:TreeViewItem IsExpanded="True">
                        <controls:TreeViewItem.Header>
                            <controlsToolkit:TreeViewItemCheckBox Content="{Binding Key}"/>
                        </controls:TreeViewItem.Header>
                        <ItemsControl ItemsSource="{Binding Value}">
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <controls:TreeViewItem>
                                    <controls:TreeViewItem.Header>
                                        <controlsToolkit:TreeViewItemCheckBox Content="{Binding Key}"/>
                                    </controls:TreeViewItem.Header>
                                        <controlsToolkit:TreeViewItemCheckBox IsChecked="{Binding Enabled}" Content="{Binding FilterTypeText}"/>
                                    </controls:TreeViewItem>
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                        </ItemsControl>
                    </controls:TreeViewItem>
                </DataTemplate>
            </Setter.Value>
        </Setter>
       </Style>


有人能把我从日常工作队的魔爪中救出来吗?什么是更干净的方法。如果我们能想出一种方法使关卡数量动态化,那就有好处了。

嗯,也许我在这里很傻,但既然你想要一个树状视图。。。为什么不使用树状视图?您还需要使用HierarchycalDataTemplate而不是普通的DataTemplate:HDT的内容成为标题,ItemsSource用于创建子节点。这也会使级别的数量变得动态


TreeView内置于WPF中,在Silverlight中作为SDK的一部分提供。

嗯,也许我在这里很傻,但既然你想要一个TreeView。。。为什么不使用树状视图?您还需要使用HierarchycalDataTemplate而不是普通的DataTemplate:HDT的内容成为标题,ItemsSource用于创建子节点。这也会使级别的数量变得动态


TreeView内置于WPF中,在Silverlight中作为SDK的一部分提供。

不知道HDT。。。看来我可以用这个。不会真正改变ItemsSource端的任何内容(这意味着我没有用于深度的递归方法)。不确定您指的是ItemsSource属性端还是数据模型端?如果是前者,请使用KeyValuePair的值,就像您现在使用的一样。因此如果是后者,则是正确的,但无论如何,您最好创建一个分层数据结构,而不是使用深度嵌套的KVP安排——这将为您提供比键和值更有意义的名称!例如,
classtreenode{stringtitle;ObservableCollection Children;}
我使用了HDT,它非常有效。有点痛苦,因为Silverlight风格要求每个“级别”都有相同的属性名称,所以我不需要“联盟”、“部门”和“团队”属性,我需要每个对象都有“选项”。我不知道HDT。。。看来我可以用这个。不会真正改变ItemsSource端的任何内容(这意味着我没有用于深度的递归方法)。不确定您指的是ItemsSource属性端还是数据模型端?如果是前者,请使用KeyValuePair的值,就像您现在使用的一样。因此如果是后者,则是正确的,但无论如何,您最好创建一个分层数据结构,而不是使用深度嵌套的KVP安排——这将为您提供比键和值更有意义的名称!例如,
classtreenode{stringtitle;ObservableCollection Children;}
我使用了HDT,它非常有效。有点痛苦,因为Silverlight风格要求每个“级别”都有相同的属性名称,所以我不需要“联盟”、“部门”和“团队”属性,而是需要每个对象都有“选项”。