如何“冻结”鼠标悬停时的 UI(主窗口)
我想要实现的是,当鼠标悬停在主窗口上时,所有 UI 元素都应该冻结,我认为可以通过将 Window.IsEnabled 设置为 false 来完成,并且在鼠标离开主窗口后,一切都应该是恢复正常。
我尝试在样式定位窗口中定义属性触发器,但它不起作用。代码很简单,
<Style.Triggers>
<Trigger Property="Window.IsMouseOver" Value="True">
<Setter Property="Window.IsEnabled" Value="false"/>
</Trigger>
</Style.Triggers>
事实上这种属性触发器在Grid上也不起作用。有人可以做出一些解释吗?
我还尝试在 Window 上显式使用 MouseEnter 和 MouseLeave 事件,并在处理程序中设置禁用/启用逻辑。这有效。我想知道是否可以在 XAML 中执行此操作?
What I want to achieve is that when the mouse is hovering over the main window, all the UI elements should freeze, which I think can be done by setting Window.IsEnabled to false, and after the mouse leaves the main window, everything should be back to normal.
I've tried to define a property trigger in a style targetting Window, but it doesn't work. The code is as lollow,
<Style.Triggers>
<Trigger Property="Window.IsMouseOver" Value="True">
<Setter Property="Window.IsEnabled" Value="false"/>
</Trigger>
</Style.Triggers>
In fact this kind of property trigger wouldn't work on Grid either. Can anyone make some explanations?
I also tried to explicitly use the MouseEnter and MouseLeave events on Window, and set the disable/enable logic in the handlers. This works. I wonder if it's possible to do this in XAML?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
老实说,我不知道为什么你的代码不起作用,我认为它会发生某种冲突,但我不知道为什么
无论如何,你可以使用 eventsetter 在 XAML 中完成它,它不是那么优雅,但它可以工作
Well to be honest I don't know why your code doesn't work, I think it goes in some kind of conflict but I don't know why
Anyway you can do it in XAML using eventsetter, It's not so elegant but it works