2009-03-10 4 views
4

W3CError 형식의 개체 컬렉션을 WPF ListView 컨트롤에 바인딩하려고했습니다. .NET WPF XAML "BindingExpression path error : ... 속성을 찾을 수 없습니다."

그것은 그것은 작동하지 않았다

 
Class W3CError 

    Public Type As ErrorOrWarning 
    Public Line As Integer 
    Public Col As Integer 
    Public Message As String 
    Public MessageId As String 
    Public Explanation As String 
    Public Source As String 

    Enum ErrorOrWarning 
     ValidationError 
     ValidationWarning 
    End Enum 

End Class 

... 좋은 작은 13 라인 클래스이었다. Visual Studio 출력 창에서 이러한 바인딩 오류가 발생했습니다.

System.Windows.Data Error: 39 : BindingExpression path error: 'Line' property not found on 'object' ''W3CError' (HashCode=...)'. BindingExpression:Path=Line; DataItem='W3CError' (HashCode=...); target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String')

음, 아니요. 속성이 아닙니다. 단순히 공개 일뿐입니다. WPF 바인딩에 대해서는 충분하지 않다고 생각하십니까?

내가 속성 보일러의 추한 69 개 라인에 내 수업을 연장하여 일을 가지고 ...

 
Class W3CError 

    Private _Type As ErrorOrWarning 
    Private _Line As Integer 
    Private _Col As Integer 
    Private _Message As String 
    Private _MessageId As String 
    Private _Explanation As String 
    Private _Source As String 

    Enum ErrorOrWarning 
     ValidationError 
     ValidationWarning 
    End Enum 

    Public Property Type() As ErrorOrWarning 
     Get 
      Return _Type 
     End Get 
     Set(ByVal value As ErrorOrWarning) 
      _Type = value 
     End Set 
    End Property 

    Public Property Line() As Integer 
     Get 
      Return _Line 
     End Get 
     Set(ByVal value As Integer) 
      _Line = value 
     End Set 
    End Property 

    Public Property Col() As Integer 
     Get 
      Return _Col 
     End Get 
     Set(ByVal value As Integer) 
      _Col = value 
     End Set 
    End Property 

    Public Property Message() As String 
     Get 
      Return _Message 
     End Get 
     Set(ByVal value As String) 
      _Message = value 
     End Set 
    End Property 

    Public Property MessageId() As String 
     Get 
      Return _MessageId 
     End Get 
     Set(ByVal value As String) 
      _MessageId = value 
     End Set 
    End Property 

    Public Property Explanation() As String 
     Get 
      Return _Explanation 
     End Get 
     Set(ByVal value As String) 
      _Explanation = value 
     End Set 
    End Property 

    Public Property Source() As String 
     Get 
      Return _Source 
     End Get 
     Set(ByVal value As String) 
      _Source = value 
     End Set 
    End Property 

End Class 

는 더 좋은 방법이 있나요?

+0

아, 내 바인딩이 작동하지 않는 이유입니다! 감사. – Kieron

+0

나는 너에게 어떤 좌절감을 덜어줬으면 좋겠다. –

답변

4

C#을 사용하는 경우 자동 속성 사용이라고 말하고 싶지만 VB에 있다고 생각하지 않습니다.

아마도 그렇지 않습니다. 추가로 이동하여 클래스가 INotifyPropertyChanged를 구현하도록하여 UI가 속성 변경 여부를 알 수 있도록 할 수도 있습니다.

+0

험버! 오히려 VB는 인라인 XML보다 자동 속성을 가지고 있습니다. –

+0

VB의 다음 버전 (.NET 4.0/Visual Studio 2010과 함께 제공되는 버전)에는 자동 속성이 있다고 생각합니다. 도움이되지는 않지만 적어도 결국은 도움이 될 것입니다. – Andy

1

더 좋은 방법은이지만, 을 구현하고 GetProperties 방법을 사용하여 필드를 가짜 속성으로 표시 할 수 있습니다. 하지만 수십개의 필드가 있다면 코드가 적어 질 것입니다.


원래는 Robert Macnee가 게시했으나 나중에 삭제되었습니다. 관심이 있으니까 여기에 복원 ...

관련 문제