自定义事件在调用时始终显示为空

编程入门 行业动态 更新时间:2024-10-21 22:51:43
本文介绍了自定义事件在调用时始终显示为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在C Sharp(Silverlight)中编写了一个自定义事件.这是代码.

Hi, I wrote a custom event in C sharp(Silverlight).Here is the code.

public delegate void MyEvent(object sender, TreeGridEventArgs e); public event MyEvent SLTreeGridSelectionChanged; void RaiseSLTreeGridSelectionChanged(TreeGridEventArgs e) { if (SLTreeGridSelectionChanged != null) { SLTreeGridSelectionChanged(this, e); } }

在这里我将调用它(在DataGrid的SelectionChanged事件期间) ..

and here I will invoke it( during the SelectionChanged event of DataGrid) ..

private void SLDataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (CurrentSELedNode != null) { TreeGridRow row = (TreeGridRow)CurrentSELedNode.Tag; RaiseSLTreeGridSelectionChanged(new TreeGridEventArgs(row)); } }

但是在引发事件时,"SLTreeGridSelectionChanged"始终显示为null.为什么会这样呢?任何的想法..?请帮助我..

but while raising the event "SLTreeGridSelectionChanged" always shows null. Why this is happening? Any idea..? Please help me..

推荐答案

只要没有订阅者,事件为null.如果您创建事件处理程序并使用+ =语法订阅事件,它将不再是null. The event is null as long as there are no subscribers. If you create an event handler and use the += syntax to subscribe for the event, it won''t be null any more.

更多推荐

自定义事件在调用时始终显示为空

本文发布于:2023-11-13 00:46:54,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1582947.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自定义   为空   事件

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!