我有不同的GroupStyle
具有这种结构:
<ListView.GroupStyle>
<GroupStyle>
<GroupStyle.ContainerStyle>
<Style TargetType="{x:Type GroupItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Expander IsExpanded="True">
<Expander.Header>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Name}" FontWeight="Bold" Foreground="Gray" FontSize="22" VerticalAlignment="Bottom" />
<TextBlock Text="{Binding ItemCount}" FontSize="22" Foreground="Green" FontWeight="Bold" FontStyle="Italic" Margin="10,0,0,0" VerticalAlignment="Bottom" />
<TextBlock Text=" Campionati" FontSize="22" Foreground="Silver" FontStyle="Italic" VerticalAlignment="Bottom" />
</StackPanel>
</Expander.Header>
<ItemsPresenter />
</Expander>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</GroupStyle.ContainerStyle>
</GroupStyle>
现在我想了解如何更改GroupStyle
的背景颜色,特别是现在它具有mahapp框架的默认颜色:
也可以设置高度尺寸?任何帮助将不胜感激。
答案 0 :(得分:1)
您可以更改扩展器的背景:
<Expander IsExpanded="True" Background="Red">
或者如果你想保留Mahapps的Themes,你应该使用Mahapps中预定义的Brushes之一,并更改Expander Style,因为Expander与有效的Accent相关。
修改强>
将此样式添加到资源:
<Style x:Key="CustomExpanderHeaderStyle" BasedOn="{DynamicResource ExpanderUpHeaderStyle}"
TargetType="{x:Type ToggleButton}">
<Setter Property="Height" Value="45"/>
<Setter Property="Background" Value="Red"/>
<Setter Property="Margin" Value="0"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ToggleButton}">
<Border Padding="{TemplateBinding Padding}"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<Grid Background="Transparent" SnapsToDevicePixels="False">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="19" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Ellipse x:Name="Circle"
Width="19"
Height="19"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Stroke="{TemplateBinding Foreground}" />
<Path x:Name="Arrow"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Stroke="{TemplateBinding Foreground}"
StrokeThickness="2"
Data="M 1,1.5 L 4.5,5 L 8,1.5"
SnapsToDevicePixels="false" />
<controls:ContentControlEx Grid.Column="1"
Margin="4 0 0 0"
Padding="{TemplateBinding Padding}"
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
Content="{TemplateBinding Content}"
ContentCharacterCasing="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(controls:ControlsHelper.ContentCharacterCasing)}"
ContentStringFormat="{TemplateBinding ContentStringFormat}"
ContentTemplate="{TemplateBinding ContentTemplate}"
ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}"
RecognizesAccessKey="True"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsChecked" Value="true">
<Setter TargetName="Arrow" Property="Data" Value="M 1,4.5 L 4.5,1 L 8,4.5" />
</Trigger>
<Trigger Property="IsMouseOver" Value="true">
<Setter TargetName="Arrow" Property="Stroke" Value="{DynamicResource GrayBrush2}" />
<Setter TargetName="Circle" Property="Stroke" Value="{DynamicResource GrayBrush2}" />
</Trigger>
<Trigger Property="IsPressed" Value="true">
<Setter TargetName="Arrow" Property="Stroke" Value="{DynamicResource BlackColorBrush}" />
<Setter TargetName="Circle" Property="Stroke" Value="{DynamicResource BlackColorBrush}" />
<Setter TargetName="Circle" Property="StrokeThickness" Value="2" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
在GroupStyle中:
<GroupStyle>
<GroupStyle.ContainerStyle>
<Style TargetType="{x:Type GroupItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Expander controls:ExpanderHelper.HeaderDownStyle="{StaticResource CustomExpanderHeaderStyle}" IsExpanded="True">
<Expander.Header>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Name}" FontWeight="Bold" Foreground="Gray" FontSize="22" VerticalAlignment="Bottom" />
<TextBlock Text="{Binding ItemCount}" FontSize="22" Foreground="Green" FontWeight="Bold" FontStyle="Italic" Margin="10,0,0,0" VerticalAlignment="Bottom" />
<TextBlock Text=" Campionati" FontSize="22" Foreground="Silver" FontStyle="Italic" VerticalAlignment="Bottom" />
</StackPanel>
</Expander.Header>
<ItemsPresenter />
</Expander>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</GroupStyle.ContainerStyle>
</GroupStyle>
不要忘记添加Xmlns:
xmlns:controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"