2013-06-13 3 views
1

에 C#을에서 코드를 변환하는 동안 내가 VB.NET에 C# 코드의 다음 조각을 변환 할이 RaisePropertyChanged - 오류 VB.NET

/// <summary> 
/// Attempts to raise the PropertyChanged event, and invokes the virtual AfterPropertyChanged 
/// method, regardless of whether the event was raised or not. 
/// </summary> 
/// <param name="propertyName"> 
/// The property which was changed. 
/// </param> 

    protected void RaisePropertyChanged(string propertyName) 
    { 
     this.VerifyProperty(propertyName); 

     PropertyChangedEventHandler handler = this.PropertyChanged; 
     if (handler != null) 
     { 
      //Get the cached event args. 
      PropertyChangedEventArgs args = GetPropertyChangedEventArgs(propertyName); 

      //Raise the PropertyChanged event. 
      handler(this, args); 
     } 
    } 

변환 후, VB 코드는 다음과 같습니다

''' <summary> 
''' Attempts to raise the PropertyChanged event, and invokes the virtual AfterPropertyChanged 
''' method, regardless of whether the event was raised or not. 
''' </summary> 
''' <param name="propertyName"> 
''' The property which was changed. 
''' </param> 
Protected Sub RaisePropertyChanged(propertyName As String) 
    Me.VerifyProperty(propertyName) 

    Dim handler As PropertyChangedEventHandler = Me.PropertyChanged 

    If handler IsNot Nothing Then 
     'Get the cached event args. 
     Dim args As PropertyChangedEventArgs = GetPropertyChangedEventArgs(propertyName) 

     'Raise the PropertyChanged event. 
     handler.Invoke(Me, args) 
    End If 
End Sub 

이벤트 및 XML 속성 등과 관련하여 완벽한 변환을 제공하지 않는 Telerik 코드 변환기를 사용했습니다.

문제는 Visual Studio에서 다음 오류를 표시합니다. 오류 '공용 이벤트 PropertyChanged (보낸 사람 개체, e As System.ComponentModel.PropertyChangedEventArgs)'이벤트이며, 직접 호출 할 수 없습니다. 'RaiseEvent'문을 사용하여 이벤트를 발생시킵니다.

내가 VB.NET 구문에서 좋은 아니에요 및 :(

+0

Dim 핸들러 As PropertyChangedEventHandler = Me.PropertyChanged – Harsha

+0

VB에서 이벤트로 작업 할 때 AddressOf를 많이 사용해야합니다. 그래서 "AddressOf Me.PropertyChanged. – Terry

답변

3

단순히 PropertyChangedEventHandler으로 희미한 핸들러를 교체 = Me.PropertyChanged PropertyChangedEventHandler = Me.PropertyChangedEvent

로 희미한 핸들러
1

가 먼저하여 PropertyChanged 변수를 정의해야합니다

이 같은

당신은 친절하게 이것 좀 도와 줄래! 공개 이벤트 PropertyChangedEventHandler하여 PropertyChanged;

+0

"을 이미 사용할 수 있습니다. – Harsha