【发布时间】:2012-03-31 12:00:13
【问题描述】:
我有一个奇怪的 WPF/XAML 问题。默认情况下,我希望扩展此 TreeView 中的所有节点。最终我会将它绑定到我的视图模型,但现在我只希望它们都默认展开。
这是有问题的代码部分(我目前正在使用)
<HierarchicalDataTemplate DataType="{x:Type Model:DirectoryItem}"
ItemsSource="{Binding Items}">
<TextBlock Text="{Binding Path=Name}"
ToolTip="{Binding Path=Path}" />
<HierarchicalDataTemplate.ItemContainerStyle>
<Style TargetType="TreeViewItem">
<Setter Property="IsExpanded" Value="True" />
</Style>
</HierarchicalDataTemplate.ItemContainerStyle>
</HierarchicalDataTemplate>
<DataTemplate DataType="{x:Type Model:FileItem}">
<TextBlock Text="{Binding Path=Name}"
ToolTip="{Binding Path=Path}" />
</DataTemplate>
特别是我将 setter 属性设置为 IsExpanded 的部分。
如下图所示,这段代码可以正常工作。如果我展开根节点,那么默认情况下所有内容都会展开。
但是为什么根节点默认不展开呢?我不知道它为什么这样做。
【问题讨论】:
标签: .net wpf xaml treeview expand