WPF工具包Datagrid的 - 你怎么把选择了吗? [英] WPF Toolkit Datagrid - how do you turn selection off?
问题描述
我在WPF DataGrid中,我绑定到一个对象。
我在那里,我希望用户能够通过和蜱他们想要的一个DataGridCheckBoxColumn。问题是,他们必须为选择然后再次单击两次,一次检查/取消选中。如何在地球上你关闭此功能,我一直在寻找的方式长时间才找到这个问题的答案。数据网格具有的SelectionMode和SelectionUnit性能 - 两者都不接受'无'或'消失'
任何帮助表示赞赏!我的代码如下,以供参考。
<我:DataGrid的保证金=15NAME =dgPreview
的AutoGenerateColumns =FALSECanUserSortColumns =真
CanUserDeleteRows =真
背景=白
ColumnHeaderHeight =20
VerticalScrollBarVisibility =可见
RowDetailsVisibilityMode =可见
>
<我:DataGrid.Columns>
<我:DataGridCheckBoxColumn了minWidth =50WIDTH =自动标题=包含绑定={结合包括}/>
<我:DataGridTextColumn了minWidth =50WIDTH =自动标题=#覆盖绑定={结合OverrideNumber}/>
<我:DataGridTextColumn了minWidth =220WIDTH =*标题=名称绑定={绑定名称}/>
<我:DataGridTextColumn了minWidth =50WIDTH =自动IsReadOnly =真头=预览绑定={结合预览}/>
< /我:DataGrid.Columns>
< /我:DataGrid的>
第一次单击放入编辑模式的单元,则在第二次点击允许你修改的复选框。您可以通过使用一个DataGridTemplateColumn而不是DataGridCheckBoxColumn更改此行为。这种替换您DataGridCheckBoxColumn:
<我:DataGridTemplateColumn了minWidth =50WIDTH =自动标题=包含 SortMemberPath =包含>
<我:DataGridTemplateColumn.CellTemplate>
<&DataTemplate的GT;
<复选框类型={StaticResource的DataGridCheckBoxStyle}=器isChecked{绑定路径=包含}/>
< / DataTemplate中>
< /我:DataGridTemplateColumn.CellTemplate>
< /我:DataGridTemplateColumn>
DataGridCheckBoxStyle只是使复选框看起来在DataGrid更好一点:
<风格X:键=DataGridCheckBoxStyle的TargetType =复选框支持算法FMP ={StaticResource的{X:类型的CheckBox}}>
< setter属性=VerticalAlignmentVALUE =中心/>
< setter属性=保证金VALUE =8,0,3,0/>
< /样式和GT;
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>
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 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工具包Datagrid的 - 你怎么把选择了吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!