用于WPF的Xceed DataGrid:复选框需要点击3次才能更改

问题描述:

我做了一个非常基本的DataGrid来测试它,但是我立即遇到了这个问题,点击复选框不会为前2次点击做任何事情。看起来它需要点击才能点击它,然后在点击第三次点击之前再点击一下鼠标点击。用于WPF的Xceed DataGrid:复选框需要点击3次才能更改

这是我使用btw的数据网格(https://xceed.com/xceed-datagrid-for-wpf/)。

GIF showing issue

XAML:

<UserControl.Resources> 
    <DataTemplate x:Key="ItemTemplate"> 
     <StackPanel> 
      <TextBlock Text="{Binding Property1}"/> 
      <CheckBox IsChecked="{Binding Property2}"/> 
     </StackPanel> 
    </DataTemplate> 
</UserControl.Resources> 
<Grid> 
    <xcdg:DataGridControl ItemTemplate="{DynamicResource ItemTemplate}" 
          ItemsSource="{Binding Collection, Source={StaticResource SampleDataSource1}}" 
          UpdateSourceTrigger="CellContentChanged" 
          Margin="10"> 
    </xcdg:DataGridControl> 
</Grid> 

的 “SampleDataSource1” 仅仅是自动生成的,但在这里它是无论如何:

<SampleDataSource1:SampleDataSource1 xmlns:SampleDataSource1="clr-namespace:Expression.Blend.SampleData.SampleDataSource1"> 
<SampleDataSource1:SampleDataSource1.Collection> 
    <SampleDataSource1:Item Property1="Cras aenean" Property2="True"/> 
    <SampleDataSource1:Item Property1="Class mauris aliquam" Property2="False"/> 
    <SampleDataSource1:Item Property1="Maecenas integer duis curae" Property2="True"/> 
    <SampleDataSource1:Item Property1="Praesent nullam nunc" Property2="False"/> 
    <SampleDataSource1:Item Property1="Nam quisque" Property2="True"/> 
    <SampleDataSource1:Item Property1="Sed accumsan" Property2="False"/> 
    <SampleDataSource1:Item Property1="Aptent vivamus aliquam aliquet" Property2="True"/> 
    <SampleDataSource1:Item Property1="Blandit donec dis" Property2="False"/> 
    <SampleDataSource1:Item Property1="Amet commodo" Property2="True"/> 
    <SampleDataSource1:Item Property1="Ante conubia" Property2="False"/> 
</SampleDataSource1:SampleDataSource1.Collection> 

所以,如果你很幸运,你会看到一个按钮,您的设计窗口一次大的举动,说:“显示配置窗口”(这似乎在使用后永远消失)。与我产生了一些XAML来解决这个问题:

<xcdg:DataGridControl ItemsSource="{Binding Source={StaticResource cvsSongs}}" 
          NavigationBehavior="RowOrCell" 
          CellEditorDisplayConditions="RowIsBeingEdited, MouseOverCell, 
          MouseOverRow, RowIsCurrent, CellIsCurrent" 
          EditTriggers="BeginEditCommand, ClickOnCurrentCell, SingleClick, 
          CellIsCurrent, ActivationGesture, RowIsCurrent"/> 

如果你知道如何使该窗口出现再次随意评论。

配置窗口信息:Xceed documentation

还有些其他人与配置窗口的问题。可能为你工作:xceed forums

您的数据网格添加这个(在xaml):

DataGridCell.GotFocus="DataGrid_GotFocus" 

,并在后面的代码中添加此:

private void DataGrid_GotFocus(object sender, RoutedEventArgs e) 
{ 
    // Lookup for the source to be DataGridCell 
    if (e.OriginalSource.GetType() == typeof(DataGridCell)) 
    { 
     // Starts the Edit on the row; 
     DataGrid grd = (DataGrid)sender; 
     grd.BeginEdit(e); 
    } 
} 
+0

感谢您的快速回答,但它不工作?没有区别,所以我感觉它没有达到功能或某种东西。智能感知识别它和一切。没有错误。我有点小事,我会错过什么吗? –

+0

我有同样的问题,但在数据网格中的组合框,这是我如何解决它,虽然它会工作appologies :) – stuicidle

+0

你试过在DataGrid_GotFocus方法中放置一个断点,只是为了看看它是否被调用? – stuicidle