这个WPF触发器有什么问题

时间:2012-04-13 16:53:31

标签: wpf xaml triggers

我有这个XAML代码抛出异常(它只是说它扔了它,没有名字)。

我用Google搜索并发现http://social.msdn.microsoft.com/Forums/en/wpf/thread/cfb159dc-d58e-41c2-81b5-c52e1272c0ce。其中说使用过的属性所做的任何更改都会引发异常。

那么在<Control.Style>

中设置触发器是不可能的

我确信这是一个非常小便的错误,因为我正在学习这项技术。

XAML代码

<Window x:Class="Triggers.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">
<Grid>
    <Button>
        <Button.Style>
            <Style TargetType="Button">
                <Style.Triggers>
                    <Trigger Property="IsMouseOver" >
                        <Setter Property="Opacity" Value="0.7" />
                    </Trigger>
                </Style.Triggers>                      
            </Style>
        </Button.Style>
        Meow
    </Button>
</Grid>

1 个答案:

答案 0 :(得分:2)

这是因为你没有告诉触发器属性IsMouseOver应该具有什么值?

试试这个:

<Trigger Property="IsMouseOver" Value="True">

要记住的是“IsMouseOver”是一个属性,而不是一个事件。所以它可以是true或false,你需要告诉WPF你的触发器适用于哪种状态。

相关问题