本文介绍了鼠标悬停时更改椭圆的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 WPF 的新手.这有点令人困惑,为什么第一个代码片段工作正常(鼠标悬停时,颜色会发生变化)但第二个代码片段不起作用?

I'm totally new in WPF. It's kind of confusing, why the first code snippet works fine (when mouse over, the color changes) but the second one doesn't work?

<Ellipse Height="50" Width="50" Opacity="0.5" Stroke="Black" >
<Ellipse.Style>
    <Style TargetType="{x:Type Ellipse}">
        <Setter Property="Fill" Value="Blue" />
        <Style.Triggers>
            <Trigger Property="IsMouseOver" Value="True">
                <Setter Property="Fill" Value="Green">
                </Setter>
            </Trigger>
        </Style.Triggers>
    </Style>
</Ellipse.Style>

//

<Ellipse Height="50" Width="50" Fill="Blue" Opacity="0.5" Stroke="Black" >
<Ellipse.Style>
    <Style TargetType="{x:Type Ellipse}">
        <Style.Triggers>
            <Trigger Property="IsMouseOver" Value="True">
                <Setter Property="Fill" Value="Green">
                </Setter>
            </Trigger>
        </Style.Triggers>
    </Style>
</Ellipse.Style>

谢谢.

推荐答案

区别在于线

<Setter Property="Fill" Value="Blue" />

阅读有关 ControlTemplates 的更多信息.

Read more on ControlTemplates.

http://msdn.microsoft.com/en-us/library/ms743230.aspx

这篇关于鼠标悬停时更改椭圆的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 00:28