WPF Toolkit Datagrid - 如何关闭选择?
我在 WPF 中有一个数据网格,我将其绑定到一个对象。
我在那里有一个 DataGridCheckBoxColumn,我希望用户能够浏览并勾选他们想要的。 问题是他们必须单击两次,一次进行选择,然后再次进行选中/取消选中。 你到底如何关闭这个功能,我一直在寻找这个问题的答案。 数据网格具有 SelectionMode 和 SelectionUnit 属性 - 两者都不接受“无”或“离开”
任何帮助表示赞赏! 我的代码如下供参考
<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>
I have a datagrid in WPF that I am binding to an object.
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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
第一次单击将单元格置于编辑模式,然后第二次单击允许您修改复选框。 您可以使用 DataGridTemplateColumn 而不是 DataGridCheckBoxColumn 来更改此行为。 将 DataGridCheckBoxColumn 替换为以下内容:
DataGridCheckBoxStyle 只是使 CheckBox 在 DataGrid 中看起来更好一些:
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:
DataGridCheckBoxStyle just makes the CheckBox look a little nicer in the DataGrid:
首先,我知道这是一个很老的问题,但我仍然认为我会尝试回答它。
几天前我遇到了同样的问题,并遇到了一个令人惊讶的简短解决方案(请参阅此博客)。 基本上,您需要做的就是将 XAML 中的
DataGridCheckBoxColumn
定义替换为以下内容:此解决方案的优点是显而易见的 - 它仅适用于 XAML; 因此,它可以有效地避免您用额外的 UI 逻辑给代码带来负担,并帮助您保持在 MVVM 狂热者眼中的地位;)。
First of, I know this is a pretty old question but I still thought I'd try and answer it.
I had the same problem a couple of days ago and came across a surprisingly short solution for it (see this blog). Basically, all you need to do is replace the
DataGridCheckBoxColumn
definition in your XAML with the following:The upside of this solution is obvious - it's XAML-only; thus it effectively refrains your from burdening your code-back with additional UI logic and helps you maintain your status in the eyes of MVVM zealots ;).