内部控件模板。触发器:
<ControlTemplate.Triggers>
<Trigger Property="UIElement.IsMouseOver" Value="True">
<Setter Property="Panel.Background" TargetName="ButtonBorder" Value="Transparent"/>
<Setter Property="Shape.Fill" TargetName="Arrow" Value="Gray"/>
</Trigger>
<Trigger Property="UIElement.IsMouseOver" Value="false">
<Setter Property="Panel.Background" TargetName="ButtonBorder" Value="Transparent"/>
<Setter Property="Shape.Fill" TargetName="Arrow" Value="Gainsboro"/>
</Trigger>
<Trigger Property="ToggleButton.IsChecked" Value="True">
<Setter Property="Panel.Background" TargetName="ButtonBorder" Value="WhiteSmoke"/>
<Setter Property="Shape.Fill" TargetName="Arrow" Value="#FF8D979E"/>
</Trigger>
<Trigger Property="UIElement.IsEnabled" Value="False">
<Setter Property="Panel.Background" TargetName="Border" Value="{StaticResource ComboBoxDisabledBackgroundBrush}"/>
<Setter Property="Panel.Background" TargetName="ButtonBorder" Value="{StaticResource ComboBoxDisabledBackgroundBrush}"/>
<Setter Property="Border.BorderBrush" TargetName="ButtonBorder" Value="{StaticResource ComboBoxDisabledBorderBrush}"/>
<Setter Property="TextElement.Foreground" Value="{StaticResource ComboBoxDisabledForegroundBrush}"/>
<Setter Property="Shape.Fill" TargetName="Arrow" Value="#999"/>
</Trigger>
</ControlTemplate.Triggers>
在前2个触发器中,我尝试更改UIElement.IsMouseOver
上的ComboBox
边界,因此我尝试设置<Setter Property="BorderBrush" TargetName="Arrow" Value="Gray"/>
,但似乎无法识别BorderBrush
。
假设您的ControlTemplate
是这样的:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="20" />
</Grid.ColumnDefinitions>
<Border Grid.ColumnSpan="2" Name="Border" ... />
<Border Grid.Column="1" Name="ButtonBorder" ... />
<Path Name="Arrow" Grid.Column="1" ... />
</Grid>
那么为了改变边框颜色,必须改变<Border Name="Border" ... >
的BorderBrush
属性。因此,您应该这样设置触发器:
<ControlTemplate.Triggers>
<Trigger Property="UIElement.IsMouseOver" Value="True">
<Setter Property="BorderBrush" TargetName="Border" Value="Red"/>
<Setter Property="Shape.Fill" TargetName="Arrow" Value="Gainsboro"/>
</Trigger>
<Trigger Property="UIElement.IsMouseOver" Value="false">
<Setter Property="BorderBrush" TargetName="Border" Value="Blue"/>
<Setter Property="Shape.Fill" TargetName="Arrow" Value="Gray"/>
</Trigger>