WPF:当父级鼠标悬停时,我可以设置 ChildElement 的 IsMouseOver 属性吗?
假设我有一个嵌套在 ListBoxItem
的 Template
中的按钮,我可以将按钮的 IsMouseOver
属性设置为 true,以便它看起来喜欢它的鼠标悬停吗?
仅供说明之用,我指的是窗口顶部的通知。它基本上是 ListBoxItem
与 TextBlock
和 Button
Suppose I have a button nested in the Template
of a ListBoxItem
, can I set the IsMouseOver
property of the button to true, so that it looks like its moused over?
Just for illustration, the notifications on the top of the window are what I am referring to. Its basically ListBoxItem
's with a TextBlock
and Button
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不幸的是,没有。 “IsMouseOver”是只读的。
不过,我假设您有一个按钮的自定义控件模板,对吧?如果是这种情况,一种解决方法是弄乱按钮的 Tag 属性。向 ControlTemplate 添加一个触发器,该触发器在设置特定标签值时触发。然后,在 ListBoxItems 的 DataTemplate 中,当项目上的 IsMouseOver 为 true 时,只需将按钮的 Tag 设置为该特定值。下面是一个例子:
Unfortunately, no. "IsMouseOver" is readonly.
I'm assuming, though, that you have a custom control template for the Button, right? If that's the case, one workaround is to mess with the Tag property of the button. Add a trigger to the ControlTemplate that gets fired when a specific Tag value is set. Then, in the DataTemplate for your ListBoxItems, just set the button's Tag to that specific value when IsMouseOver on the item is true. Below is an example: