开发者

Problem in converting the code form vb.net to c#

VB Code:

Public Event PropertyChanged(ByVal sender As Object, ByVal e As PropertyChangedEventArgs) Implements INotifyPropertyChanged.PropertyChanged

Public Sub OnPropertyChanged(ByVal e As PropertyChangedEventArgs)
  If PropertyChangedEvent IsNot Nothing Then
    RaiseEvent PropertyChanged(Me, e)
  End If
End Sub

Converted C# code

public event PropertyChangedEventHandler INotifyPropertyChanged.PropertyChanged;

public delegate void PropertyChangedEventHandler(object sender, PropertyChangedEventArgs e);

public void OnPropertyChanged(PropertyChangedEventArgs e)
{
    if (PropertyChangedEvent != null) {
  开发者_运维技巧      if (PropertyChanged != null) {
            PropertyChanged(this, e);
        }
    }
}

Error is:

Error 1 The name 'PropertyChangedEvent' does not exist in the current context


Your event is called "PropertyChanged", not "PropertyChangedEvent".
Also, the event is explicitly implemented, which means, you'd have to use this: ((INotifyPropertyChanged)this).PropertyChanged instead of PropertyChanged to access the event.
And as Oded pointed out, the code checks twice for the event. You can remove one of those checks.


Don't use explicit interface implementation but just make it a public method.

Or cast this to the interface to call the handler. ((INotifyPropertyChanged)this).PropertyChanged

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜