如何获得发件人的价值 [英] How to get sender's value

查看:94
本文介绍了如何获得发件人的价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在调试已触发事件时,我在Watch窗口中查看了对象发件人

In debugging a fired event, I viewed the object sender in the Watch window

void SelectAssetGraphic(object sender, SelectionChangedEventArgs e) {  }



在发件人下,我可以看到发件人的项目,例如其中一个是GraphicsLayer.ID(其值='手机')。在立即绕线器中,当我输入

sender.GraphicsLayer.ID

返回的消息喜欢:

'object'不包含'GraphicsLayer'的定义并没有扩展方法'GraphicsLayer'接受'object'类型的第一个参数可以找到(你是否缺少using指令或汇编引用?

获取的方法是什么?来自发件人的价值?谢谢。


Under the sender, I could see Sender's items, e.g. one of them is GraphicsLayer.ID (its value='phones'). In the Immediate Winder, when I entered
sender.GraphicsLayer.ID
The returning message liked that:
'object' does not contain a definition for 'GraphicsLayer' and no extension method 'GraphicsLayer' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?
What's the approach to get the value from sender? Thanks.

推荐答案

需要将对象发送者强制转换为产生事件的对象,例如

object sender needs to be cast to the object that produced the event e.g
Button b = (Button)sender;





如果您知道它是什么对象,否则执行以下操作:





That is if you know what object it is, otherwise do something like this:

if(sender is Button)
{
Button b = (Button)sender;
}


这篇关于如何获得发件人的价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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