自定义事件在调用时始终显示为空 [英] Custom Event always Showing null While invoking

查看:82
本文介绍了自定义事件在调用时始终显示为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在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.


这篇关于自定义事件在调用时始终显示为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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