2012-08-02 8 views
0

내 View Model의 속성에 바인딩 된 DataGrid (이 경우 C1 DataGrid)가 있습니다. WPF에서 바인딩하는 양방향 데이터 바인딩

 <c1:C1DataGrid 
      AutoGenerateColumns="False" 
      IsReadOnly="False" 
      Margin="5" Width="auto" 
      MinWidth="250" 
      HorizontalAlignment="Stretch" 
      VerticalAlignment="Stretch" 
      Name="dgNotifAssign" 
      CanUserAddRows="True" 
      ItemsSource="{Binding Path=notifCodeSubs.notification_configuration}" 
      > 


      <c1:C1DataGrid.Columns> 
       <c1:DataGridTextColumn 
        Binding="{Binding Path=user_id}" 
        Header="Recipient" 
        VerticalAlignment="Stretch" 
        SortMemberPath="user_id" 
        > 

가 내 뷰 모델에, 바인딩 된 속성은 다음과 같습니다

: 코드 숨김에서

Public Property notifCodeSubs As dsPeruseFM 
    Get 
     If _notifCode Is Nothing Then 
      _notifCode = New dsPeruseFM 
     End If 
     Return _notifCode 
    End Get 
    Set(ByVal value As dsPeruseFM) 
     MsgBox("If you can see this, success!") 
    End Set 
End Property 

내가 뷰 모델의 인스턴스를 생성하고 데이터 그리드에 대한 XAML은 다음과 같습니다

: ...

Dim vm As New ctrlAlertNotifyVM 

뿐만 아니라 오히려 간단합니다 인스턴스에 대한 XAML의 데이터 컨텍스트를 설정

위의 구성은 데이터를 올바르게 컴파일하고 읽습니다. 그리드는 모든 올바른 데이터로 채워집니다. 문제는 데이터 격자의 ItemsSource에 Mode=twoway을 추가하려고 할 때 발생합니다. 그 시점 VS2010 다음과 같은 오류 내뱉는에서 :

A TwoWay or OneWayToSource binding cannot work on the read-only property 'notification_configuration' of type 'PeruseFM.dsPeruseFM'.

을 내 모든 속성은 읽기/쓰기 것을 매우 확신합니다. 이것에 대한 set 명령은이 시점에서 메시지 상자 일 뿐이지 만 액세스 할 수있는 것처럼 보이지는 않습니다.

질문은 ... 전에이 문제를 만난 사람이 있습니까?

업데이트에 대한 응답, "notification_configuration의 모양은 무엇입니까?" sixlettervariables에서 : notifCodeSubs가 읽기/쓰기 것을 당신은 우리를 표시했습니다

Public Function codeChanged(Optional ByVal x As String = "") 

    If _notifCode Is Nothing Then 
     _notifCode = New dsPeruseFM 
    End If 
    taNotifSubs.fillNotifSubs(notifCode:=x, dataTable:=_notifCode.notification_configuration) 
    Return _notifCode 
End Function 
+0

'notification_configuration '은 어떤 모양입니까? – user7116

답변

1

, 그러나, 당신이에 바인딩 한 실제 재산이 아니다.

...read-only property 'notification_configuration'...

따라서 당신이 ItemsSource로 해당 속성에 결합하는 TwoWay를 적용 할 수 없습니다 :이 관점에서

는 오류 메시지가 매우 자명하다.

관련 문제