如何在 XAML 中设置边框的 MouseOver 事件/触发器?
我希望当鼠标位于边框上方时边框变为绿色,然后当鼠标不再位于边框上方时返回蓝色。
我尝试这样做,但没有任何运气:
<Border
Name="ClearButtonBorder"
Grid.Column="1"
CornerRadius="0,3,3,0"
Background="Blue">
<Border.Triggers>
<Trigger Property="Border.IsMouseOver" Value="True">
<Setter Property="Border.Background" Value="Green" />
</Trigger>
<Trigger Property="Border.IsMouseOver" Value="False">
<Setter Property="Border.Background" Value="Blue" />
</Trigger>
</Border.Triggers>
<TextBlock
HorizontalAlignment="Center"
VerticalAlignment="Center"
Text="X" />
</Border>
如何为 MouseOver 设置触发器或事件?
I want the border to turn green when the mouse is over it and then to return to blue when the mouse is no longer over the border.
I attempted this without any luck:
<Border
Name="ClearButtonBorder"
Grid.Column="1"
CornerRadius="0,3,3,0"
Background="Blue">
<Border.Triggers>
<Trigger Property="Border.IsMouseOver" Value="True">
<Setter Property="Border.Background" Value="Green" />
</Trigger>
<Trigger Property="Border.IsMouseOver" Value="False">
<Setter Property="Border.Background" Value="Blue" />
</Trigger>
</Border.Triggers>
<TextBlock
HorizontalAlignment="Center"
VerticalAlignment="Center"
Text="X" />
</Border>
How can one set a trigger or events for MouseOver?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,这很令人困惑......
根据 这篇博文,看起来这是 WPF 的遗漏。
为了使它工作,你需要使用一种样式:
我想这个问题并不常见,因为大多数人倾向于将这种东西分解成一种样式,所以它可以在多个控件上使用。
Yes, this is confusing...
According to this blog post, it looks like this is an omission from WPF.
To make it work you need to use a style:
I guess this problem isn't that common as most people tend to factor out this sort of thing into a style, so it can be used on multiple controls.