DataGrid의 유효성 검사와 관련하여 문제가 있습니다. 모델 클래스에서 IDataErrorInfo 유효성 검사를 사용하고 있습니다.CellTemplate 및 CellEditingTemplate이있는 DataGrid의 IDataErrorInfo 유효성 검사
문제는 별도의 CellTemplate 및 CellEditingTemplate 편집 가능한 데이터 그리드에 (참고하지 않은 널 (null) 속성입니다 - 검증은 null 또는 비어있는 경우 오류를 반환) :
저장 버튼을<!-- some other validated columns -->
<DataGridTemplateColumn Header="Note">
<DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<TextBox Name="textBoxNote" Text="{Binding Note, ValidatesOnDataErrors=True}" />
</DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Note}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
나는 MyObject.Error 유효성을 확인 속성을 반환하고 null이 아니면 MessageBox를 표시합니다. 문제는 첫 번째 열 (노트 하나가 아닌)을 유효한 값으로 변경 한 다음 저장 버튼을 클릭하면 .Error 속성이 null입니다. Note 속성의 ValidatesOnDataError와의 바인딩이 발생하지 않았으므로 (예상하지 못한) 예상되는 동작입니다. (TextBox 컨트롤은 결코 존재하지 않았습니다!). 그러나 TextBlock에서 ValidatesOnDataErrors를 true로 설정하면 DataGrid에 표시되는 모든 객체 (예 : 데이터베이스)에서 원하지 않는 유효성 검사를 받게됩니다. 유효성 검사도이 경우에 많은 시간이 걸릴 수 있습니다 ...
이 문제를 해결하는 올바른 방법은 무엇입니까? 모델 클래스에서 유효성을 유지하고 싶습니다 (개체가 유효한지 여부를 알아야합니다). 코드 숨김 (버튼 이벤트 저장)에서 행 바인딩 객체의 유효성을 강제로 검사 할 수있는 방법이 있습니까? 또는 어떻게 든 초기화해야합니다. 객체 생성시 오류가 있습니까? 다른 아이디어?
편집 : 전체 행 (모든 셀)을 편집 모드 (CellEditingTemplate)에 넣을 수 있습니까? 그런 다음, 모든 컨트롤을로드 할 것이고, 데이터 바인딩, 이것은 또한 ... 모든
감사합니다, 는 DB