更改ISMouseOver上的ComboBox边框按钮

时间:2015-07-22 05:26:30

标签: wpf combobox styles

ConrtolTemplate.Triggers内部:

    <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个触发器中,我尝试更改ComboBox上的UIElement.IsMouseOver边框,因此我尝试设置<Setter Property="BorderBrush" TargetName="Arrow" Value="Gray"/>,但似乎无法识别BorderBrush

1 个答案:

答案 0 :(得分:0)

假设您的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>

然后,为了更改边框颜色,BorderBrush的{​​{1}}属性必须更改。因此,您应该像这样设置触发器:

<Border Name="Border" ... >