如何在 Silverlight 上为堆栈面板创建鼠标悬停状态?

发布于 2024-08-01 16:37:29 字数 265 浏览 5 评论 0原文

我正在尝试创建一个鼠标悬停状态,当鼠标位于堆栈面板上时,它会更改其不透明度。

我已经创建了状态,并为堆栈面板创建了 mouse_enter 事件,并且在 cs 文件后面的代码中,我在 Mouse_Enter 事件上有以下代码。

MouseOver.Begin();

其中 MouseOver 是 StoryBoard 的名称,但是当我的鼠标悬停在堆栈面板上甚至单击堆栈面板时,什么也没有发生,我错过了什么?

谢谢

玩孩子

I am trying to create a mouse hover state which it changes its opacity when a mouse is over the stack panel.

I have created the state, and created a mouse_enter event for the stack panel, and on the code behind cs file, I have the following code on Mouse_Enter event.

MouseOver.Begin();

Where MouseOver is the StoryBoard's name, but when my mouse is hovering over the stack panel or even click on the stack panel, nothing happened, what am I missing?

Thanks

PlayKid

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

小傻瓜 2024-08-08 16:37:29

我自己想通了。

用这段代码:

VisualStateManager.GoToState

谢谢大家。

I figured out myself.

With this code:

VisualStateManager.GoToState

Thanks everyone.

我只土不豪 2024-08-08 16:37:29

您确定已触发该事件(您已正确连接该事件)吗? 尝试使用消息框或其他方式进行检查。 (System.Windows.MessageBox.Show())

您确定情节提要在其他情况下工作正常吗(在页面加载或其他情况下尝试过吗?)

如果这两种情况都有效,请解释一下您如何添加事件处理程序。

Are you sure that the event is fired (you have wired up the event properly) ? Try checking using a message box or something. (System.Windows.MessageBox.Show())

Are you sure the storyboard works well in other situations (tried it on page load or something?)

If both these work, please explain how you went about adding the event handler.

枫以 2024-08-08 16:37:29

根据我的经验,将 Mouse_Enter 事件连接到面板不起作用,因为面板内的内容最终会窃取该事件。 我通常的解决方案是设置一个透明目标,覆盖我想要鼠标事件的区域,并将该项目保留在可视化树的顶部。 因此,XAML 看起来类似于:

<StackPanel x:Name="ContentPanel" SizeChanged="ContentPanelSizeChanged" >
    < /*Some content here */ >
</StackPanel>
<Canvas x:Name="HitTarget" Mouse_Enter="HitTargetMouseEnter" />

然后 ContentPanelSizeChanged 处理程序将 HitTarget Canvas 的大小设置为 StackPanel 的实际(渲染)大小。 同样的事情适用于 MouseButtonDown 事件,我认为它也适用于 MouseWheel 事件。 我建议尝试 Senthil 的故障排除建议,但如果您根本无法触发事件(我认为这就是问题所在),请尝试一下。

In my experience, hooking up a Mouse_Enter event to the panel doesn't work because the content inside the panel ends up stealing the event. My usual solution is to set up a transparent target that covers the area that I want mouse events for and keep that item on the top of the visual tree. So the XAML looks something like:

<StackPanel x:Name="ContentPanel" SizeChanged="ContentPanelSizeChanged" >
    < /*Some content here */ >
</StackPanel>
<Canvas x:Name="HitTarget" Mouse_Enter="HitTargetMouseEnter" />

And then the ContentPanelSizeChanged handler sets the size of the HitTarget Canvas to be the actual (rendered) size of the StackPanel. Same thing works for MouseButtonDown events and I would presume it works for MouseWheel events as well. I'd recommend trying Senthil's troubleshooting suggestions, but if you can't get the event to fire at all (which I would presume is the problem), give this a try.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文