Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/271.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用触发器或任何其他事件更改wpf中onmoveover、onmouseleave的按钮颜色_C#_Wpf_Button_Triggers - Fatal编程技术网

C# 如何使用触发器或任何其他事件更改wpf中onmoveover、onmouseleave的按钮颜色

C# 如何使用触发器或任何其他事件更改wpf中onmoveover、onmouseleave的按钮颜色,c#,wpf,button,triggers,C#,Wpf,Button,Triggers,我开发了一个带有一些按钮的WPF应用程序。现在我想通过使用触发器或任何其他事件来更改mouseover、onmouseleave和onmouseenter上这些按钮的颜色。 有什么建议吗 提前感谢。在所需的事件中,您可以像这样设置背景颜色 // Change the background color of button1 to Blue button1.Background = Brushes.Blue; 您还可以在触发器中设置: <!-- Button will change from

我开发了一个带有一些按钮的WPF应用程序。现在我想通过使用触发器或任何其他事件来更改mouseover、onmouseleave和onmouseenter上这些按钮的颜色。 有什么建议吗
提前感谢。

在所需的事件中,您可以像这样设置背景颜色

// Change the background color of button1 to Blue
button1.Background = Brushes.Blue;
您还可以在触发器中设置:

<!-- Button will change from Blue to Yellow on MouseOver -->
<Style TargetType="{x:Type Button}">
    <Setter Property="Background" Value="Blue" />
    <Style.Triggers>
        <Trigger Property="IsMouseOver" Value="True">
            <Setter Property="Background" Value="Yellow" />
        </Trigger>
    </Style.Triggers>
</Style>


有关更多详细信息,请查看文章的属性触发器部分。

在这个问题中可以找到此解决方案的问题:同样的问题发生在我身上——它似乎不会设置背景。