【问题标题】:Expand all TreeView nodes展开所有 TreeView 节点
【发布时间】:2012-07-30 12:47:09
【问题描述】:

如何展开这段代码中的所有节点?

<TreeView ItemsSource="{Binding Path=.}" Height="220" HorizontalAlignment="Left" Margin="224,0,0,0" Name="treeView1" VerticalAlignment="Top" Width="162">
        <TreeView.ItemTemplate >
            <HierarchicalDataTemplate ItemsSource="{Binding Path=Children}">
                <StackPanel Orientation="Horizontal">
                    <CheckBox IsChecked="{Binding Path=IsChecked}" Focusable="False" Uid="{Binding Path=Id}" Click="CheckBox_Click"/>
                    <TextBlock Text="{Binding Path=Name}" Uid="{Binding Path=Id}"/>    
                </StackPanel>

            </HierarchicalDataTemplate>
        </TreeView.ItemTemplate>
    </TreeView>

【问题讨论】:

    标签: c# wpf xaml treeview nodes


    【解决方案1】:

    您可以拥有一个布尔属性,例如IsExapnded 在与树视图项绑定的类上。将 IsExapnded 的默认值设置为 true 并将其与树视图项的 IsExpanded 属性绑定。

    它将展开所有节点。

    或者如果你只想在 xaml 中处理,你可以这样写:

    <TreeView>
         <TreeView.ItemContainerStyle>         
           <Style TargetType="{x:Type TreeViewItem}">            
             <Setter Property="IsExpanded" Value="True" />         
           </Style>     
        </TreeView.ItemContainerStyle> 
    </TreeView> 
    

    【讨论】:

      【解决方案2】:

      使用这个:

      <TreeView.ItemContainerStyle>
          <Style TargetType="TreeViewItem">
              <Setter Property="IsExpanded" Value="True" />
          </Style>
      </TreeView.ItemContainerStyle>
      

      【讨论】:

      • 谢谢,这正是我需要的。
      • @Willem,别再回答他的问题了,也许他会:)。
      猜你喜欢
      • 2013-11-10
      • 2011-08-02
      • 2016-11-18
      • 2012-03-10
      • 1970-01-01
      • 1970-01-01
      • 2011-05-30
      • 2014-07-08
      • 2014-01-02
      相关资源
      最近更新 更多