简体   繁体   English

如何在TreeView中隐藏根文件夹?

[英]How to hide Root folder in TreeView?

I load the file into a file and I make a TreeView in WPF MVVM. 我将文件加载到文件中,并在WPF MVVM中创建TreeView。 When I get the UI, I do not want to see my root folder. 当获得UI时,我不想看到我的根文件夹。 How to do that, can anyone help me? 怎么做,有人可以帮我吗? How to hide root folder? 如何隐藏根文件夹? Her is a code for treeview and for style. 她是树状视图和样式的代码。

 <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> 

instead of adding root TreeViewItem <TreeViewItem Margin="10" ItemsSource="{Binding Children}"/> bind ItemsSource of TreeView: 而不是添加根TreeViewItem <TreeViewItem Margin="10" ItemsSource="{Binding Children}"/>绑定TreeView的ItemsSource:

 <TreeView DataContext="{Binding RootItem}"
           ItemsSource="{Binding Children}" 
           Template="{StaticResource TreeViewTemplate}"/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM