如何展开此代码中的所有节点?
<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>
答案 0 :(得分:3)
您可以拥有一个布尔属性,例如IsExapnded在您的类上,它与树视图项绑定。将IsExapnded的默认值设置为true,并将其与treeview项的IsExpanded属性绑定。
它将扩展所有节点。
如果你只想在xaml中处理,你可以像这样写:
<TreeView>
<TreeView.ItemContainerStyle>
<Style TargetType="{x:Type TreeViewItem}">
<Setter Property="IsExpanded" Value="True" />
</Style>
</TreeView.ItemContainerStyle>
</TreeView>
答案 1 :(得分:1)
使用此:
<TreeView.ItemContainerStyle>
<Style TargetType="TreeViewItem">
<Setter Property="IsExpanded" Value="True" />
</Style>
</TreeView.ItemContainerStyle>