zoukankan      html  css  js  c++  java
  • 【转载】关于treeview的多层显示的科学用法!

    http://blogs.msdn.com/b/mikehillberg/archive/2009/10/30/treeview-and-hierarchicaldatatemplate-step-by-step.aspx 这是原文,虽然看着方法成功了,但是原文的DataContext绑定我却没有成功,我是直接itemssource绑定的。

    <TreeView ItemsSource="{Binding League}">
       
        <!-- Conference template -->
        <TreeView.ItemTemplate>
            <HierarchicalDataTemplate ItemsSource="{Binding Teams}">
                <TextBlock Foreground="Red" Text="{Binding Name}" />
               
                <!-- Team template -->
                <HierarchicalDataTemplate.ItemTemplate>
                    <HierarchicalDataTemplate ItemsSource="{Binding Players}">
                        <TextBlock Text="{Binding Name}" />
     
                        <!-- Player template -->
                        <HierarchicalDataTemplate.ItemTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding}" />
                            </DataTemplate>
                        </HierarchicalDataTemplate.ItemTemplate>
                       
                    </HierarchicalDataTemplate>
                </HierarchicalDataTemplate.ItemTemplate>
               
            </HierarchicalDataTemplate>
        </TreeView.ItemTemplate>
       
    </TreeView>
    var western = new Conference("Western")
    {
        Teams =
        {
            new Team("Club Deportivo Chivas USA"),
            new Team("Colorado Rapids"),
            new Team("FC Dallas"),
            new Team("Houston Dynamo"),
            new Team("Los Angeles Galaxy"),
            new Team("Real Salt Lake"),
            new Team("San Jose Earthquakes"),
            new Team("Seattle Sounders FC"),
            new Team("Portland 2011"),
            new Team("Vancouver 2011")
        }
    };
    var eastern = new Conference("Eastern")
    {
        Teams =
        {
            new Team("Chicago Fire"),
            new Team("Columbus Crew"),
            new Team("D.C. United"),
            new Team("Kansas City Wizards"),
            new Team("New York Red Bulls"),
            new Team("New England Revolution"),
            new Team("Toronto FC"),
            new Team("Philadelphia Union 2010")
        }
    };
    var league = new Collection<Conference>() { western, eastern };
    DataContext = new
    {
        WesternConference = western,
        EasternConference = eastern,
        League = league
    };
  • 相关阅读:
    利用mybatis-generator自动生成代码
    gradle安装
    有关﹤![CDATA[ ]]> 说明
    mysql时间字段转换为毫秒格式
    string 与BigDecimal互转
    VLOOKUP多条件查找不使用辅助列
    BIEE-CSS样式大全
    VBA【遍历每个工作表并将工作表表名赋予B2单元格】
    深入理解公式{1,0}的用法
    DB2解锁
  • 原文地址:https://www.cnblogs.com/rarator/p/3229517.html
Copyright © 2011-2022 走看看