VB.Net引发事件问题 [英] VB.Net Raise Events problem

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

问题描述

你好,我试图研究如何克服这个错误

公共事件propertyChanged(发送者作为对象,e作为system.componentmodelchangedeventargs)"是一个事件,不能直接调用,请使用"RaisedEvent"语句引发事件."


这是有问题的代码:

Hello I have tried to look into how its possible to overcome this error

"Public event propertyChanged(Sender as object, e as system.componentmodelchangedeventargs)''is an event and cannot be called directly, use a ''RaisedEvent'' Statement to raise an event."


Here is the code in question:

Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
       Private Sub OnPropertyChanged(ByVal info As String)
           Dim handler As PropertyChangedEventHandler = PropertyChanged
           If handler IsNot Nothing Then
               handler(Me, New PropertyChangedEventArgs(info))
           End If
       End Sub




我已经试过了:




I have tried this:

Private Sub OnPropertyChanged(ByVal info As String)
            Dim handler As PropertyChangedEventHandler = PropertyChanged
            RaiseEvent PropertyChanged()
            If handler IsNot Nothing Then
                handler(Me, New PropertyChangedEventArgs(info))
            End If



但随后出现错误:在线RaiseEvent PropertyChanged()

未为参数``公共事件属性的发送方已更改(发送方作为对象,)e指定为参数e作为system.componentmodel.propertychangedeventargs)''


我敢肯定这种类型的过程很简单,但是需要帮助来理解这个概念.在此先感谢您



but then get an error: on line RaiseEvent PropertyChanged()

Argument not specified for parameter ''sender of public event property changed(sender as object,) e As system.componentmodel.propertychangedeventargs)''


I am pretty sure this type of procedure is simple but need help to grasp the concept thank you in advance

推荐答案

您需要指定参数,例如错误告诉您.像这样的东西:
You need to specify the parameters like the error is telling you. Something like this:
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs("MyProperty"))


之后,您可能需要将代码更改为如下所示:


You might want to change the code after that to something like this:

If handler IsNot Nothing Then
   handler.Invoke(Me, New PropertyChangedEventArgs("MyProperty"))
End If


另外,您是否真的需要引发一个事件然后自己再次调用处理程序?看起来有些奇怪.

祝你好运!


Also, do you realy need to raise an event and then call the handler again yourself? Looks somewhat strange.

Good luck!


这篇关于VB.Net引发事件问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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