首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >IsMouseOver in UserControl

IsMouseOver in UserControl
EN

Stack Overflow用户
提问于 2014-08-29 22:59:33
回答 1查看 1.4K关注 0票数 0

我试图捕获-修改IsMouseOver以更改MouseEnter和MouseLeave上按钮的BackColor:

代码语言:javascript
复制
 <UserControl x:Class="TVSlide.TitleBarButton"
                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                 xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                 mc:Ignorable="d"
                 d:DesignHeight="400" d:DesignWidth="400">

        <Grid>
            <Button Name="TButton">
                <Button.Style>
                    <Style>
                        <Setter Property="Button.Background" Value="Blue"/>
                        <Style.Triggers>
                            <Trigger Property="Button.IsMouseOver" Value="True">
                                <Setter Property="Button.Background" Value="Yellow" />
                            </Trigger>
                        </Style.Triggers>
                    </Style>
                </Button.Style>

            </Button>

            <!--<Button Name ="TButton" Content="Button" HorizontalAlignment="Left" VerticalAlignment="Top"
                    Width="121" Height="44" Background="#FFEC0D0D" />-->
        </Grid>
    </UserControl>

仍然得到可怕的冰蓝色而不是黄色。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-08-30 07:19:06

您需要覆盖按钮模板并删除默认的铬。

这是一个样本

代码语言:javascript
复制
<Button Name="TButton"
        Content="A button">
    <Button.Style>
        <Style TargetType="Button">
            <Setter Property="Background"
                    Value="Blue" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Button}">
                        <Grid x:Name="border"
                              Background="{TemplateBinding Background}"
                              SnapsToDevicePixels="true">
                            <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                              Margin="{TemplateBinding Padding}"
                                              RecognizesAccessKey="True"
                                              SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                              VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsEnabled"
                                     Value="false">
                                <Setter Property="Foreground"
                                        Value="{StaticResource {x:Static SystemColors.InactiveCaptionTextBrushKey}}" />
                                <Setter Property="Opacity"
                                        TargetName="border"
                                        Value="0.5" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Style.Triggers>
                <Trigger Property="IsMouseOver"
                         Value="True">
                    <Setter Property="Background"
                            Value="Yellow" />
                </Trigger>
            </Style.Triggers>
        </Style>
    </Button.Style>
</Button>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25577306

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档