Wpf 在Xceed DataGridControl中单击可编辑绑定复选框

Wpf 在Xceed DataGridControl中单击可编辑绑定复选框,wpf,checkbox,xceed-datagrid,Wpf,Checkbox,Xceed Datagrid,在过去的一个小时里,我一直在寻找一个简单问题的解决方案:如何在Xceed的社区DataGridControl中创建一个单击可编辑的绑定复选框 需要明确的是:我需要一个复选框列,用户可以在其中单击任何复选框,而不管选择了哪一行,并相应地更改视图模型的IsSelected属性 下面是我尝试过的最新排列。此代码从模型中读取值,但由于某种原因,单击复选框不会调用IsSelectedsetter <xcdg:DataGridControl x:Name="DictionariesDataGridCo

在过去的一个小时里,我一直在寻找一个简单问题的解决方案:如何在Xceed的社区
DataGridControl
中创建一个单击可编辑的绑定
复选框

需要明确的是:我需要一个
复选框
列,用户可以在其中单击任何
复选框
,而不管选择了哪一行,并相应地更改视图模型的
IsSelected
属性

下面是我尝试过的最新排列。此代码从模型中读取值,但由于某种原因,单击
复选框
不会调用
IsSelected
setter

<xcdg:DataGridControl x:Name="DictionariesDataGridControl" ItemsSource="{Binding Mode=OneWay, Source={StaticResource DictionariesViewSource}}" AutoCreateColumns="False" AutoRemoveColumnsAndDetailConfigurations="False" SelectionMode="Extended" NavigationBehavior="RowOnly">
    <xcdg:DataGridControl.View>
        <xcdg:TableView UseDefaultHeadersFooters="False" ShowRowSelectorPane="False" VerticalGridLineThickness="0">
            <xcdg:TableView.FixedHeaders>
                <DataTemplate>
                    <xcdg:ColumnManagerRow BorderThickness="0"/>
                </DataTemplate>
            </xcdg:TableView.FixedHeaders>
        </xcdg:TableView>
    </xcdg:DataGridControl.View>
    <xcdg:DataGridControl.Columns>
        <xcdg:Column FieldName="IsSelected" MinWidth="20" MaxWidth="20" CellEditorDisplayConditions="RowIsCurrent">
            <xcdg:Column.CellContentTemplate>
                <DataTemplate>
                    <CheckBox IsChecked="{Binding ., Mode=OneWay}" IsHitTestVisible="False"/>
                </DataTemplate>
            </xcdg:Column.CellContentTemplate>
            <xcdg:Column.CellEditor>
                <xcdg:CellEditor>
                    <xcdg:CellEditor.EditTemplate>
                        <DataTemplate>
                            <CheckBox IsChecked="{Binding ., Mode=TwoWay}"/>
                        </DataTemplate>
                    </xcdg:CellEditor.EditTemplate>
                </xcdg:CellEditor>
            </xcdg:Column.CellEditor>
        </xcdg:Column>
    </xcdg:DataGridControl.Columns>
Xceed任意将背景色设置为蓝色是多么奇怪的决定

编辑3

使用@JBrooks的答案,我尝试了以下方法:

<xcdg:Column FieldName="IsSelected" MinWidth="20" MaxWidth="20" CellEditorDisplayConditions="Always">
    <xcdg:Column.CellEditor>
        <xcdg:CellEditor>
            <xcdg:CellEditor.EditTemplate>
                <DataTemplate>
                    <CheckBox IsChecked="{Binding ., Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
                </DataTemplate>
            </xcdg:CellEditor.EditTemplate>
        </xcdg:CellEditor>
    </xcdg:Column.CellEditor>
</xcdg:Column>


不幸的是,由于某些原因,
IsSelected
属性上的setter在我选中该框时从未被调用。不过,getter会被调用多次,并且
复选框在初始绑定时正确显示。

您既有CellContentTemplate又有CellEditor,因此第一次单击会执行“进入编辑模式”逻辑。只要一个像下面这样的。这是一个普通的WPF数据网格,但也许您可以尝试类似的网格

  <DataGridTemplateColumn Header="Active" SortMemberPath="IsActive"  >
     <DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
           <CheckBox IsChecked="{Binding IsActive, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" IsEnabled="{Binding IsEnabled}" Style="{StaticResource rightsCB}" />
        </DataTemplate>
    </DataGridTemplateColumn.CellTemplate>
  </DataGridTemplateColumn>

对于此DataGrid,我还设置了以下属性:

SelectedItem=“{Binding SelectedUser,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}
SelectionUnit=“FullRow”SelectionMode=“Single”


因此,此DataGrid的行为与您想要的一样-我单击第4行中的复选框,IsChecked将发生更改,它还将第4行设置为当前行,将SelectedUser设置为绑定到第4行的用户。

这显然是
DataGridCheckBox
中的已知错误。代码审查到此为止。。。我说的“this”是指蓝色背景的愚蠢。3个问题:输出窗口中有什么东西吗?您是否有与捕获的事件类似的内容?当复选框失去焦点时是否设置了setter?1。输出窗口中没有任何内容,没有。不过,我没有打开任何特殊的日志记录。2.我明确连接到的唯一事件是
ItemsSourceChangeCompleted
,以填充集合视图的
SortDescriptions
集合。3.无论我如何操作复选框,都不会调用setter,包括更改选择、使用
TAB
键等。可能会重复
<xcdg:Column FieldName="IsSelected" MinWidth="20" MaxWidth="20" CellEditorDisplayConditions="Always">
    <xcdg:Column.CellEditor>
        <xcdg:CellEditor>
            <xcdg:CellEditor.EditTemplate>
                <DataTemplate>
                    <CheckBox IsChecked="{Binding ., Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
                </DataTemplate>
            </xcdg:CellEditor.EditTemplate>
        </xcdg:CellEditor>
    </xcdg:Column.CellEditor>
</xcdg:Column>
  <DataGridTemplateColumn Header="Active" SortMemberPath="IsActive"  >
     <DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
           <CheckBox IsChecked="{Binding IsActive, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" IsEnabled="{Binding IsEnabled}" Style="{StaticResource rightsCB}" />
        </DataTemplate>
    </DataGridTemplateColumn.CellTemplate>
  </DataGridTemplateColumn>