我的 WPF 应用程序视图中有 Datagrid,我在行标题中使用复选框。
<DataGrid.RowHeaderTemplate>
<DataTemplate>
<Grid >
<CheckBox BorderThickness="0"
Command="{Binding DataContext.AssignPartsToGroupCommand, RelativeSource={RelativeSource FindAncestor,
AncestorType={x:Type UserControl}}}"
>
<CheckBox.CommandParameter>
<MultiBinding Converter="{StaticResource PartsGroupAssignConverter}">
<Binding Path="IsChecked" RelativeSource="{RelativeSource Self}" Mode="OneWay"/>
<Binding RelativeSource="{RelativeSource Mode=FindAncestor,
AncestorType={x:Type DataGridRow}}"
Path="DataContext" Mode="OneWay"/>
</MultiBinding>
</CheckBox.CommandParameter>
<CheckBox.IsChecked>
<MultiBinding Converter="{StaticResource PartsGroupAssignedConverter}" Mode="OneWay">
<Binding ElementName="partsGroupGrid" Path="SelectedItem.id"></Binding>
<Binding RelativeSource="{RelativeSource Mode=FindAncestor,
AncestorType={x:Type DataGridRow}}"
Path="DataContext" Mode="OneWay"/>
<Binding Path="IsSelected" Mode="OneWay"
RelativeSource="{RelativeSource FindAncestor,
AncestorType={x:Type DataGridRow}}"
/>
</MultiBinding>
</CheckBox.IsChecked>
</CheckBox>
</Grid>
</DataTemplate>
如您所见,我将 CheckBox 属性“IsSelected”绑定到多个值,其中之一是 DataGrid 行选择:
<Binding Path="IsSelected"
Mode="OneWay"
RelativeSource="{RelativeSource FindAncestor,
AncestorType={x:Type DataGridRow}}"
/>
我的问题是 - 当我通过选择行检查 CheckBox 时,不会触发链接到 CheckBox 的命令。但是当我手动(使用鼠标)执行此操作时它会触发。我该如何解决这个问题?