我将文件加载到文件中,并在WPF MVVM中创建TreeView。 当获得UI时,我不想看到我的根文件夹。怎么做,有人可以帮我吗?如何隐藏根文件夹?她是树状视图和样式的代码。
<GroupBox Margin="10" Header="DSC Configurations" HorizontalAlignment="Center" Height="850" Width="500"> <TreeView DataContext="{Binding RootItem}" Template="{StaticResource TreeViewTemplate}"> <TreeViewItem Margin="10" ItemsSource="{Binding Children}"/> </TreeView> </GroupBox> <Style TargetType="{x:Type TreeViewItem}"> <Setter Property="ItemContainerStyle" Value="{StaticResource TreeViewItemStyle}"/> <Setter Property="ItemsSource" Value="{Binding Children}"/> <Setter Property="ItemTemplate" Value="{StaticResource CheckBoxItemTemplate}" /> <Setter Property="Margin" Value="10" /> <Setter Property="IsExpanded" Value="True" /> </Style>
答案 0 :(得分:1)
代替添加根TreeViewItem <TreeViewItem Margin="10" ItemsSource="{Binding Children}"/>
绑定TreeView的ItemsSource:
<TreeView DataContext="{Binding RootItem}"
ItemsSource="{Binding Children}"
Template="{StaticResource TreeViewTemplate}"/>