2017-09-20 66 views
0

我已經加載自定義列的DataGrid單元格中的複選框,我喜歡限制該列的編輯操作因此,我已自定義外部列,然後使複選框屬性IsHitTestVisible爲false以限制使用鼠標編輯複選框。但是我可以使用鍵盤(Space鍵)更改複選框的狀態。如何避免這種情況,並使複選框完全處於不可編輯狀態。如何限制鍵盤操作以更改複選框值?

代碼snippet`

< CustomDataGrid x:Name="dataGrid" 
        Editing="True" IsReadOnly="True" 
        Grouping="True" 
        AutoPopulateColumns="False" 
        DataSource="{Binding Path=OrdersDetails}"> 
    < CustomDataGrid.Columns> 
//I like to restrict the editing for the Closed column, Like IsReadOnly property of the Text-Box, 
I am able to achieve this using the IsHitVisible as false,This helps only for mouse click But I am not able to restrict the key opeartion 
      <MyDataGridCheckBoxColumn Text="Closed" Items="{Binding IsClosed}" /> 
    < CustomDataGrid.Columns> 
<CustomDataGrid/> 
` 
+0

你目前試過什麼?代碼示例? –

+0

Hi @GingerNinja請在我的網格中找到我使用的代碼 – James

+0

您是否嘗試過使用ControlTemplates? –

回答

0

雖然不清楚您所有的自定義列和要求。這應該能夠用給定列的Template來解決。我嘲笑了一個簡單的例子:

<DataGrid ItemsSource="{Binding Tester}" Width="280"> 
     <DataGrid.Columns> 
      <DataGridTextColumn Header="Name" Width="100" IsReadOnly="True" Binding="{Binding Name}"/> 
      <DataGridTextColumn Header="Value" Width="100" IsReadOnly="True" Binding="{Binding Value}"/> 
      <DataGridTemplateColumn Header="Checked" Width="80"> 
       <!-- Should be able to put a similar Template on MyDataGridCheckBoxColumn--> 
       <DataGridTemplateColumn.CellTemplate> 
        <DataTemplate> 
         <CheckBox IsChecked="{Binding IsChecked}" IsHitTestVisible="False"> 
         </CheckBox> 
        </DataTemplate> 
       </DataGridTemplateColumn.CellTemplate> 
      </DataGridTemplateColumn> 
     </DataGrid.Columns> 
    </DataGrid> 

與此我無法更改與鼠標和鍵盤的複選框。