可以
我找到了解决办法。基本上,我需要构建DataTrigger并检查其中的类别,如果它匹配,则使用不同的GroupStyle。以下是一个例子:
<ControlTemplate TargetType="{x:Type GroupItem}"
x:Key="defaultGroup">
<ItemsPresenter />
</ControlTemplate>
<ListView.GroupStyle>
<GroupStyle >
<GroupStyle.ContainerStyle>
<Style TargetType="{x:Type GroupItem}">
<Setter Property="Margin"
Value="0,0,0,5" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GroupItem}">
<Expander IsExpanded="False"
BorderBrush="Black"
BorderThickness="3"
Padding="5,1,1,5">
<Expander.Header>
<DockPanel>
<TextBlock FontWeight="Bold"
Margin="0"
Width="250">
<TextBlock.Text>
<MultiBinding StringFormat="{}{0} ({1} jobs)">
<Binding Path="Name" />
<Binding Path="ItemCount" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
<TextBlock FontWeight="Bold"
Text="{Binding Path=Items[0].Category, StringFormat=T}" />
</DockPanel>
</Expander.Header>
<Expander.Content>
<ItemsPresenter />
</Expander.Content>
</Expander>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<DataTrigger Binding="{Binding Items[0].Category}"
Value="ABC">
<Setter Property="Template"
Value="{StaticResource defaultGroup}" />
</DataTrigger>
</Style.Triggers>
</Style>
</GroupStyle.ContainerStyle>
</GroupStyle>
</ListView.GroupStyle>