• VMTreeView:NotificationObject


     public class VMTreeView:NotificationObject
        {
            public ObservableCollection<OneNode> OneNodeList { get; set; }

            public VMTreeView()
            {
                OneNodeList = new ObservableCollection<OneNode>();

                ObservableCollection<OneNode> NodeList1 = new ObservableCollection<OneNode>();
                NodeList1.Add(new OneNode { GuoJia = "青岛1" });
                NodeList1.Add(new OneNode { GuoJia = "青岛2" });

                ObservableCollection<OneNode> NodeList2 = new ObservableCollection<OneNode>();
                NodeList2.Add(new OneNode { GuoJia = "菏泽", NodeList = NodeList1 });
                NodeList2.Add(new OneNode { GuoJia = "青岛" });

                ObservableCollection<OneNode> OneNodeList1 = new ObservableCollection<OneNode>();

                OneNodeList1.Add(new OneNode { GuoJia = "山东", NodeList = NodeList2 });
                OneNodeList1.Add(new OneNode { GuoJia = "广东" });

                OneNodeList.Add(new OneNode { GuoJia = "中国", NodeList = OneNodeList1 });
                OneNodeList.Add(new OneNode { GuoJia = "美国", });
               // OneNodeList.Add(new OneNode { GuoJia = "韩国" });

                RaisePropertyChanged(string.Empty);
            }
        }

        public class OneNode
        {
            public string GuoJia { get; set; }

            public ObservableCollection<OneNode> NodeList { get; set; }
        }

    <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="auto"></ColumnDefinition>
                <ColumnDefinition Width="auto"></ColumnDefinition>
            </Grid.ColumnDefinitions>
            <Grid.Resources>

                <HierarchicalDataTemplate  x:Key="OneNode" ItemsSource="{Binding NodeList}">
                    <TextBlock Text="{Binding Path=GuoJia}"/>
                </HierarchicalDataTemplate>

                <HierarchicalDataTemplate x:Key="TwoNode"
                                    ItemsSource = "{Binding Path=TwoNodeList}">
                    <TextBlock Text="{Binding Path=Name}"/>
                </HierarchicalDataTemplate>

                <XmlDataProvider x:Key="treeData" XPath="*">
                    <x:XData>
                        <Items Name="Items" xmlns="">
                            <Item1/>
                            <Item2>
                                <Item22/>
                                <Item12/>
                                <Item13>
                                    <Item131/>
                                    <Item131/>
                                </Item13>
                            </Item2>
                        </Items>
                    </x:XData>
                </XmlDataProvider>
                <HierarchicalDataTemplate ItemsSource="{Binding XPath=child::*}"   x:Key="template">
                    <TextBlock Name="textBlock" Text="{Binding Name}"/>
                </HierarchicalDataTemplate>

            </Grid.Resources>

            <TreeView Grid.Column="0">
                <TreeView.Items>
                    <TreeViewItem Header="根节点1">
                        <TreeViewItem Header="根节点1.1"></TreeViewItem>
                        <TreeViewItem ItemsSource="{Binding Source={StaticResource OneNode}}" Header="My Soccer Leagues" />
                    </TreeViewItem>
                    <TreeViewItem Header="根节点2" IsExpanded="True">
                        <TreeViewItem Header="根节点2.1"></TreeViewItem>

                        <TreeViewItem IsExpanded="True" ItemTemplate="{StaticResource OneNode}" ItemsSource="{Binding OneNodeList}" Header="My Soccer Leagues" />
                    </TreeViewItem>
                </TreeView.Items>
            </TreeView>

            <TreeView Grid.Column="1" ItemTemplate="{StaticResource template}"
               ItemsSource="{Binding Source={StaticResource treeData}}">
            </TreeView>
        </Grid>

     <Grid>
            <TreeView ItemsSource="{Binding DataSource}" x:Name="trv_Menu" Margin="5">
                <TreeView.ItemTemplate>
                    <HierarchicalDataTemplate>
                        <StackPanel Orientation="Horizontal">
                            <Image Source="..\..\Resource\Menu.png" Margin="2"/>
                            <TextBlock Text="{Binding Name}" Margin="2"/>
                        </StackPanel>
                    </HierarchicalDataTemplate>
                </TreeView.ItemTemplate>
                <Event:Interaction.Triggers>
                    <Event:EventTrigger EventName="SelectedItemChanged" SourceName="trv_Menu">
                        <GalaCommand:EventToCommand Command="{Binding ShowContentCommand}"
                                                   CommandParameter="{Binding ElementName=trv_Menu,Path=SelectedItem}"/>  
                    </Event:EventTrigger>
                </Event:Interaction.Triggers>
            </TreeView>
        </Grid>

  • 相关阅读:
    静态查找表和动态查找表
    内存分配
    常用不等式
    考研线性代数(向量,线性方程组)
    考研线性代数(矩阵)
    考研线性代数(行列式)
    微积分常用思想方法小结
    bug修复集合(不定期更新)
    上下文对象及servletContext接口
    手动编解码解决get提交错误的问题
  • 原文地址:https://www.cnblogs.com/iwangjun/p/2432599.html
Copyright © 2020-2023  润新知