2012-09-25 9 views
0

WPF DataGrid와 관련하여 질문이 있습니다. IDataErrorInfo 유효성 검사를 위해 모든 선택된 행을 편집으로 설정하고 싶습니다. 즉, 모든 셀의 셀 템플릿을 CellTemplate에서 CellEditingTemplate으로 설정한다는 의미입니다.전체 선택된 DataGrid 행 템플릿을 CellEditingTemplate으로 설정하십시오.

<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> 

는 XAML (일종의 트리거)의 가능성이있다 :

이것은 예를 들어 한 열이인가? 코드 숨김에서 어떻게 할 수 있습니까? 두 개의 개별 스타일을 리소스로 사용하여 솔루션을 찾은 다음 Row_Selected 및 Row_Unselected 이벤트에서 프로그래밍 방식으로 전환 할 수 있지만 별도의 CellTemplate 및 CellEditingTemplate이있는 열에 XAML 코드를 사용하는 것이 좋습니다.

누구나 올바른 방법을 가르쳐 줄 수 있습니까?

미리 감사드립니다. 감사합니다. DB

답변

0

좋아요, 전체 행을 편집 모드로 만들지 못했지만 IDataErrorInfo 개체 (IDataErrorInfo 유효성 검사의 종류)를 다시 유효화했습니다. 이것은 CellEditingTemplate의 컨트롤을 ValidateOnDataErrors = True로 개체 속성에 바인딩하기 위해 행의 모든 ​​셀에 편집 모드를 설정하려는 이유였습니다. 그렇지 않으면 DataGrid에 새 객체를 추가했지만 속성 (편집 된 객체 제외)은 유효성이 확인되지 않았습니다. 사용자가 데이터 그리드에 새 개체를 추가 할 때 내가 수동으로 설정하는 myNewObject.Revalidate() 메서드를 호출 이제

public virtual void Revalidate() // never needed to override though 
{ 
    Type type = this.GetType(); 

    // "touch" all of the properties of the object - this calls the indexer that checks 
    // if property is valid and sets the object's Error property 
    foreach (PropertyInfo propertyInfo in type.GetProperties()) 
    {     
     var indexerProperty = this[propertyInfo.Name]; 
    } 
} 

: 내 모델 객체 (즉 IDataErrorInfo를 확장)의 모든 슈퍼 클래스에서

나는이 방법을 추가 개체를 데이터베이스에 저장하기 전에 확인하는 Error 속성

감사합니다. DB