无法更改IsMousehover事件触发器上的RepeatButton背景

时间:2018-08-03 12:39:58

标签: c# wpf xaml mousehover

我用自旋控件制作了一个文本框。

enter image description here

我只想在鼠标悬停在这些按钮上而不是在“文本框”的鼠标悬停时更改“ +”,“-”按钮的背景颜色。

这是带有微调框的文本框的样式

        <Style x:Key="PlushMinus"  TargetType="{x:Type RepeatButton}">
        <Style.Triggers>
            <Trigger Property="IsMouseOver" Value="True">
                <Setter Property="Background"  Value="#18689a"/>
            </Trigger>
        </Style.Triggers> 
    </Style>
    <Style x:Key="SpinButton"  TargetType="Slider">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Slider">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="20"/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition/>
                            <RowDefinition Height="0"/>
                            <RowDefinition/>
                        </Grid.RowDefinitions>
                        <TextBox Grid.RowSpan="3" Background="#057aa5" BorderBrush="#FFABADB3" Text="{Binding Value,Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" BorderThickness="1,1,0,1" HorizontalContentAlignment="Left" VerticalContentAlignment="Center" Padding="2.8,1.55,0,0" Foreground="White"/>
                        <RepeatButton Style="{StaticResource PlushMinus}" Name="BtnPlush" Grid.Column="1" Grid.Row="0" Command="Slider.IncreaseLarge" BorderThickness="0,0,0,.5" BorderBrush="Transparent" Background="#2da5da">
                            <fa:ImageAwesome Margin="0,.5,0,0" Icon="Plus" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="White" Height="6" Width="6"/>

                        </RepeatButton>
                        <Rectangle Grid.Column="1" Grid.Row="1" Fill="Red" Height="0"/>
                        <RepeatButton Style="{StaticResource PlushMinus}" Name="BtnMinus" Grid.Column="1" Grid.Row="2" Command="Slider.DecreaseLarge" BorderThickness="0,.5,0,0" BorderBrush="Transparent" Background="#2da5da">
                            <fa:ImageAwesome Margin="0,0,0,0" Icon="Minus" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="White" Height="6" Width="6"/>
                        </RepeatButton>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger  Property="RepeatButton.IsMouseOver" Value="True">
                            <Setter TargetName="BtnPlush" Property="Background"  Value="#18689a"/>
                        </Trigger>
                        <Trigger Property="RepeatButton.IsMouseOver" Value="True">
                            <Setter TargetName="BtnMinus" Property="Background"  Value="#18689a"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

谢谢。

任何帮助都是有意义的。

0 个答案:

没有答案