所以,我有一個樹狀圖,我有一個列表。我想對它應用一個過濾器,並且所有不符合過濾器上單詞的節點都會崩潰,所以它們不佔用空間。WPF摺疊TreeView中的節點
的問題是,即使我將它們設置爲崩潰,他們仍然需要最小的空間量...
<TreeView x:Name="UserTree">
<TreeView.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}"
Color="Transparent" />
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}"
Color="Black" />
<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}"
Color="Transparent" />
<local:SumConverter x:Key="sumConverter"/>
</TreeView.Resources>
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding UserList}">
<Border x:Name="headerTree" Background="#FFD3D1D1" CornerRadius="3" Padding="2"
Margin="2">
<Grid Width="330" Height="20">
<TextBlock Text="{Binding Name}" Name="txtGroupName" Width="280"
Height="20" FontFamily="Palatino Linotype" Foreground="Black" VerticalAlignment="Center"
AllowDrop="True" Drop="TextBlock_Drop" Padding="5,0,0,0" HorizontalAlignment="Left"
Margin="0,2,0,0" />
<CheckBox x:Name="cbSelector" HorizontalAlignment="Right"
VerticalAlignment="Center" Margin="0,0,5,0" Checked="cbSelector_Checked"
Unchecked="cbSelector_Unchecked" />
</Grid>
</Border>
<HierarchicalDataTemplate.ItemTemplate>
<DataTemplate>
<Grid Width="320" Visibility="{Binding isVisible}">
<CheckBox Margin="16,1,1,1" VerticalAlignment="center"
Checked="ChkUser_Checked" Unchecked="chkUser_Unchecked"
IsChecked="{Binding IsListed}"
PreviewMouseMove="CheckBox_PreviewMouseMove"
PreviewMouseLeftButtonDown="CheckBox_PreviewMouseLeftButtonDown" ToolTipService.ToolTip="
{Binding Section}">
<CheckBox.Content>
<MultiBinding Converter="{StaticResource sumConverter}">
<Binding Path="Name"/>
<Binding Path="Status"/>
</MultiBinding>
</CheckBox.Content>
</CheckBox>
<Image Source="{Binding ImagemStatus}" Width="16" Height="16"
HorizontalAlignment="Left" Margin="0,2,0,0" />
<Button x:Name="btnRemoveFromGroup" Click="btnRemoveFromGroup_Click" HorizontalAlignment="Right" Width="16px" Height="16px"
VerticalAlignment="Top" Style="{StaticResource MyButtonStyle}" Foreground="{x:Null}"
ToolTipService.ToolTip="Remove from group" Content="
{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type
TreeViewItem}, AncestorLevel=2}, Path=DataContext.ObtainGroup}">
<Button.Background>
<ImageBrush ImageSource="Imagens/Grp.png"/>
</Button.Background>
</Button>
</Grid>
</DataTemplate>
</HierarchicalDataTemplate.ItemTemplate>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
<TreeView.ItemContainerStyle>
<Style TargetType="{x:Type TreeViewItem}">
<Setter Property="IsExpanded" Value="{Binding IsExpanded}"></Setter>
</Style>
</TreeView.ItemContainerStyle>
</TreeView>
<Style x:Key="MyButtonStyle" TargetType="Button">
<Setter Property="OverridesDefaultStyle" Value="True"/>
<Setter Property="Margin" Value="5"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border Name="border"
BorderThickness="0"
Padding="4,2"
BorderBrush="DarkGray"
CornerRadius="3"
Background="{TemplateBinding Background}">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="border" Property="BorderBrush" Value="Black" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
摺疊不會從實例(從內存)中刪除它們,您將不得不處置這些節點的實例 – Shaharyar
因此,擺脫空間的唯一方法是將它們移動到另一個列表(例如)或刪除它? – HDD
移動他們不會將他們從內存中刪除,你將不得不處置 – Shaharyar