[英]How to hide wpf expander header
我在列表视图中有一个扩展器。 几个分组附加到它,问题是有时分组名称不适用于某些行。 所以它向我显示了一个空的扩展器标题,在这种情况下我希望隐藏。 任何帮助将不胜感激。 谢谢。
前任。 不是所有的东西都有一个“组”..
<ListView.GroupStyle>
<GroupStyle>
<GroupStyle.ContainerStyle>
<Style TargetType="{x:Type GroupItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Expander IsExpanded="True" >
<Expander.HeaderTemplate>
<DataTemplate>
</DataTemplate>
</Expander.HeaderTemplate>
<Expander.Header>
<StackPanel Orientation="Horizontal" >
<TextBlock Text="{Binding Name}" FontWeight="Bold" Foreground="Gray" FontSize="14" VerticalAlignment="Bottom" />
<TextBlock Text="{Binding ItemCount}" FontSize="14" Foreground="Green" FontWeight="Bold" FontStyle="Italic" Margin="10,0,0,0" VerticalAlignment="Bottom" />
</StackPanel>
</Expander.Header>
<ItemsPresenter />
</Expander>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</GroupStyle.ContainerStyle>
</GroupStyle>
</ListView.GroupStyle>
items.Add(new User() { Name = "D", Age = 42, Question = "First", Category = "Dependecies",Character="Blank" });
items.Add(new User() { Name = "E", Age = 39, Question = "First", Category = "Variables", Expression = "Exp1" });
items.Add(new User() { Name = "F", Age = 13, Question = "First", Category = "Rules", Expression = "Exp1" });
items.Add(new User() { Name = "V", Age = 13, Question = "First", Category = "Rules", Expression = "Exp1", Group = "A" });
items.Add(new User() { Name = "W", Age = 13, Question = "First", Category = "Rules", Expression = "Exp1", Group = "A" });
items.Add(new User() { Name = "Z", Age = 13, Question = "First", Category = "Rules", Expression = "Exp1", Group = "B" });
CollectionView view = (CollectionView)CollectionViewSource.GetDefaultView(listView.ItemsSource);
PropertyGroupDescription groupDescription = new PropertyGroupDescription("Question");
view.GroupDescriptions.Add(groupDescription);
CollectionView view2 = (CollectionView)CollectionViewSource.GetDefaultView(listView.ItemsSource);
PropertyGroupDescription groupDescription2 = new PropertyGroupDescription("Category");
view2.GroupDescriptions.Add(groupDescription2);
CollectionView view3 = (CollectionView)CollectionViewSource.GetDefaultView(view2);
PropertyGroupDescription groupDescription3 = new PropertyGroupDescription("Group");
view3.GroupDescriptions.Add(groupDescription3);
也许有人还需要它......
<ListView.GroupStyle>
<GroupStyle>
<GroupStyle.ContainerStyle>
<Style TargetType="{x:Type GroupItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<!-- STEP 1: ADD MOTHER CONTAINER -->
<Grid>
<Expander x:Name="expander1" IsExpanded="True" >
<Expander.Header>
<StackPanel Orientation="Horizontal" >
<TextBlock Text="{Binding Name}" FontWeight="Bold" Foreground="Gray" FontSize="14" VerticalAlignment="Bottom" />
<TextBlock Text="{Binding ItemCount}" FontSize="14" Foreground="Green" FontWeight="Bold" FontStyle="Italic" Margin="10,0,0,0" VerticalAlignment="Bottom" />
</StackPanel>
</Expander.Header>
<ItemsPresenter />
</Expander>
<!-- STEP 2: THIS IS THE TRICK Visibility="Collapsed" -->
<ItemsPresenter x:Name="item" Visibility="Collapsed" />
</Grid>
<!-- STEP 3: THIS IS THE MAGIC, ControlTemplate.Triggers -->
<ControlTemplate.Triggers>
<DataTrigger Binding="{Binding Path=Name}" Value="{x:Null}">
<Setter TargetName="expander1" Property="Visibility" Value="Collapsed"></Setter>
<Setter TargetName="item" Property="Visibility" Value="Visible"></Setter>
</DataTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</GroupStyle.ContainerStyle>
</GroupStyle>
</ListView.GroupStyle>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.