活动-以编程方式WPF [英] Events - programmatically WPF

查看:130
本文介绍了活动-以编程方式WPF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我试图在不使用XAML功能的情况下将鼠标悬停事件添加到堆栈面板.我怎样才能做到这一点?我确实希望堆栈面板中的文本在鼠标悬停时改变颜色.我可能需要将事件应用于堆栈面板中的标签,但这并不是太重要.我只需要知道如何编写代码即可?
Jib

Hey all,
I''m trying to add a mouseover event to a stackpanel without using the XAML functionality. How can I do this? I literally want the text within the stackpanel to change color on mouse over. I may need to apply the event to the labels within the stackpanel, but that''s not too important. I just need to know how to code it please?
Jib

推荐答案

您可以在后面的代码中获取StackPanel的对象,

You can get the object of the StackPanel in the code behind,

<br />
StackPanel myPanel = new StackPanel();<br />
myPanel.MouseMove += new MouseEventHandler(myPanel_MouseMove);<br />
<br />
void myPanel_MouseMove(object sender, MouseEventArgs e) {<br />
        //Do your stuff here<br />
}<br />


谢谢.我现在遇到了另一个问题.

我有一个包含网格的按钮. thge网格的一部分包含一幅图像.另一个是带有标签的堆栈面板.将鼠标悬停在按钮上时,我希望将标签的字体颜色更改为黑色.如何以编程方式做到这一点?

臂架
Thank you. I''ve now run into another problem.

I have a button that contains a grid. One part of thge grid contains an image,. the other a stackpanel with labels in it. On mouseover of the button I wish to change the font color of the labels to black. How can I do that programmatically?

Jib


这篇关于活动-以编程方式WPF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆