WPF Toolkit Datagrid - 如何关闭选择? [英] WPF Toolkit Datagrid - how do you turn selection off?

查看:24
本文介绍了WPF Toolkit Datagrid - 如何关闭选择?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 WPF 中有一个数据网格,我绑定到一个对象.

I have a datagrid in WPF that I am binding to an object.

我在那里有一个 DataGridCheckBoxColumn,我希望用户能够通过并勾选他们想要的.问题是他们必须单击两次,一次用于选择,然后再次选中/取消选中.你到底怎么把它关掉,我一直在寻找方法来找到这个问题的答案.数据网格具有 SelectionMode 和 SelectionUnit 属性 - 它们都不接受none"或go away"

I have a DataGridCheckBoxColumn on there which I want the users to be able to go through and tick the ones they want. Problem is they have to click twice, once for selection then again to check/uncheck. How on earth do you turn this off, I've been searching for way to long to find the answer to this. The datagrid has SelectionMode and SelectionUnit properties - neither of which accept 'none' or 'go away'

感谢任何帮助!我的代码如下供参考

Any help is appreciated! My code is below for reference

<my:DataGrid Margin="15"  Name="dgPreview" 
        AutoGenerateColumns="False" CanUserSortColumns="True" 
             CanUserDeleteRows="True" 
             Background="White" 
             ColumnHeaderHeight="20" 
             VerticalScrollBarVisibility="Visible" 
             RowDetailsVisibilityMode="Visible" 
             >

    <my:DataGrid.Columns>
        <my:DataGridCheckBoxColumn  MinWidth="50" Width="Auto" Header="Include" Binding="{Binding Include}" />
        <my:DataGridTextColumn MinWidth="50"  Width="Auto" Header="Override #" Binding="{Binding OverrideNumber}" />
        <my:DataGridTextColumn MinWidth="220" Width="*" Header="Name" Binding="{Binding Name}" />
        <my:DataGridTextColumn MinWidth="50" Width="Auto" IsReadOnly="True"  Header="Preview" Binding="{Binding Preview}" />
    </my:DataGrid.Columns>
</my:DataGrid>

推荐答案

第一次单击将单元格置于编辑模式,然后第二次单击允许您修改复选框.您可以通过使用 DataGridTemplateColumn 而不是 DataGridCheckBoxColumn 来更改此行为.用这个替换你的 DataGridCheckBoxColumn:

The first click puts the cell in edit mode then the second click allows you to modify the checkbox. You can change this behavior by using a DataGridTemplateColumn instead of a DataGridCheckBoxColumn. Replace your DataGridCheckBoxColumn with this:

<my:DataGridTemplateColumn MinWidth="50" Width="Auto" Header="Include" SortMemberPath="Include">
   <my:DataGridTemplateColumn.CellTemplate>
      <DataTemplate>
         <CheckBox Style="{StaticResource DataGridCheckBoxStyle}" IsChecked="{Binding Path=Include}" />
      </DataTemplate>
   </my:DataGridTemplateColumn.CellTemplate>
</my:DataGridTemplateColumn>

DataGridCheckBoxStyle 只是让 CheckBox 在 DataGrid 中看起来更漂亮一些:

DataGridCheckBoxStyle just makes the CheckBox look a little nicer in the DataGrid:

<Style x:Key="DataGridCheckBoxStyle" TargetType="CheckBox" BasedOn="{StaticResource {x:Type CheckBox}}">
   <Setter Property="VerticalAlignment" Value="Center" />
   <Setter Property="Margin" Value="8,0,3,0" />
</Style>

这篇关于WPF Toolkit Datagrid - 如何关闭选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆