MyException - 我的异常网
当前位置:我的异常网» Silverlight » wpf样式触发器鼠标划过按钮有关问题

wpf样式触发器鼠标划过按钮有关问题

www.MyException.Cn  网友分享于:2013-02-18  浏览:100次
wpf样式触发器鼠标划过按钮问题

<Window x:Class="WpfTest.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Window.Resources>
        <Style x:Key="Style1" TargetType="{x:Type Button}">
            <Setter Property="FontSize" Value="16"></Setter>
            <Style.Triggers>
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter Property="Background" Value="BlanchedAlmond"></Setter>
                    <Setter Property="Cursor" Value="Hand" />
                </Trigger>
            </Style.Triggers>
        </Style>
    </Window.Resources>
    <Grid>
        <Button Style="{StaticResource Style1}" Margin="23,32,95,139" Content="按钮1"/>
    </Grid>
</Window>

请问前辈们,为什么鼠标划过按钮,然后停留在按钮上面,背景色只显示一下BlanchedAlmond颜色,然后又恢复默认的颜色,谢谢!

------解决方案--------------------
不知道你的是怎么回事,你可以尝试换一种写法,给Button一个name属性,比如Name=“Button1”,代码这样写:
<Trigger Property="IsMouseOver" Value="True">
                                        <Setter Property="Background" TargetName="Button1">
                                            <Setter.Value>
                                                <SolidColorBrushColor="BlanchedAlmond" />
                                            </Setter.Value>
                                        </Setter>
</Trigger>

我的代码是这样写的,显示正常,不知道你的怎么回事。

文章评论

软件开发程序错误异常ExceptionCopyright © 2009-2015 MyException 版权所有