IntegerUpDown样式上/下按钮

问题描述 投票:0回答:1

我正在尝试设置integerupdown(Xceed框架)控件的样式以及我缺乏的wpf知识。到目前为止,我已经为除OnMouseOver之外的所有内容设置了样式,OnMouseOver看起来仍然像是“常规”按钮的鼠标悬停。

如何在鼠标悬停时设置样式?删除蓝色的自动背景。

MouseOverLooksUgly

    <UserControl.Resources>
    <Style x:Key="{x:Static theme:ResourceKeys.SpinnerButtonStyleKey}" TargetType="RepeatButton">
        <Setter Property="Foreground" Value="#fff" />
        <Setter Property="BorderThickness" Value="0" />
        <Setter Property="Background" Value="#555555"></Setter>
        <Style.Triggers>
            <Trigger Property="IsMouseOver" Value="True">
                <Setter Property="Background" Value="Red"></Setter>
                <Setter Property="Background" Value="Black"></Setter>
            </Trigger>
        </Style.Triggers>
    </Style>
    <Style TargetType="{x:Type xctk:IntegerUpDown}">
        <Style.Resources>
            <SolidColorBrush x:Key="{x:Static theme:ResourceKeys.GlyphNormalForegroundKey}"  Color="#e9e9ee"/>
        </Style.Resources>
    </Style>
</UserControl.Resources>
wpf xceed
1个回答
0
投票

您应该为RepeatButton资源定义自定义的themes:ResourceKeys.SpinnerButtonStyleKey样式:

<xctk:IntegerUpDown
            xmlns:themes="clr-namespace:Xceed.Wpf.Toolkit.Themes;assembly=Xceed.Wpf.Toolkit"
            xmlns:chrome="clr-namespace:Xceed.Wpf.Toolkit.Chromes;assembly=Xceed.Wpf.Toolkit">
    <xctk:IntegerUpDown.Resources>
        <Style x:Key="{x:Static themes:ResourceKeys.SpinnerButtonStyleKey}" 
                       TargetType="RepeatButton">
            <Setter Property="Background" Value="{DynamicResource {x:Static themes:ResourceKeys.ButtonNormalBackgroundKey}}" />
            <Setter Property="BorderBrush" Value="{DynamicResource {x:Static themes:ResourceKeys.ButtonNormalOuterBorderKey}}" />
            <Setter Property="BorderThickness" Value="1" />
            <Setter Property="Padding" Value="2,2" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="RepeatButton">
                        <Grid>
                            <chrome:ButtonChrome x:Name="Chrome"
                                       BorderBrush="{TemplateBinding BorderBrush}" 
                                       Background="{TemplateBinding Background}"                                                                  
                                       CornerRadius="{DynamicResource {x:Static themes:ResourceKeys.SpinButtonCornerRadiusKey}}"
                                       RenderEnabled="{TemplateBinding IsEnabled}"
                                       RenderMouseOver="False"
                                       RenderNormal="True"
                                       RenderPressed="{TemplateBinding IsPressed}"
                                       SnapsToDevicePixels="true" />
                            <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                                      VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                                      Margin="{TemplateBinding Padding}" />
                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter Property="Background" Value="Red" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </xctk:IntegerUpDown.Resources>
</xctk:IntegerUpDown>
© www.soinside.com 2019 - 2024. All rights reserved.