2013-06-05 2 views
0

정보가있는 행이있는 WPF MVVM에서 데이터 격자를 만들려고하는데 열은 Boolean 속성을 나타내는 DataGridCheckBoxColumn입니다.한 번의 클릭으로 행 선택을 비활성화하고 확인란을 활성화하는 방법은 무엇입니까?

확인란을 클릭하여 원 클릭으로 '확인'으로 변경하고 싶습니다. 또한 행 선택 옵션을 비활성화하고 다른 열의 다른 옵션을 변경하는 옵션을 비활성화하려고합니다.

상담하십시오. 출발점으로이 답변을 사용

답변

0

: How to perform Single click checkbox selection in WPF DataGrid?

나는 일부 수정했고,이 함께 상처 :

WPF :

<DataGrid.Resources> 
    <Style TargetType="{x:Type DataGridRow}"> 
    <EventSetter Event="PreviewMouseLeftButtonDown" Handler="DataGridRow_PreviewMouseLeftButtonDown"/> 
    </Style> 
    <Style TargetType="{x:Type DataGridCell}"> 
    <EventSetter Event="PreviewMouseLeftButtonDown" Handler="DataGridCell_PreviewMouseLeftButtonDown"/> 
    </Style> 
</DataGrid.Resources> 

코드 숨김

private void DataGridRow_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) 
    { 
     DataGridRow row = sender as DataGridRow; 
     if (row == null) return; 
     if (row.IsEditing) return; 
     if (!row.IsSelected) row.IsSelected = true; // you can't select a single cell in full row select mode, so instead we have to select the whole row 
    } 

    private void DataGridCell_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) 
    { 
     DataGridCell cell = sender as DataGridCell; 
     if (cell == null) return; 
     if (cell.IsEditing) return; 
     if (!cell.IsFocused) cell.Focus(); // you CAN focus on a single cell in full row select mode, and in fact you HAVE to if you want single click editing. 
     //if (!cell.IsSelected) cell.IsSelected = true; --> can't do this with full row select. You HAVE to do this for single cell selection mode. 
    } 

그것을 시도하고 그것이 당신이 원하는 것을하는지보십시오.

관련 문제