私はPOSアプリケーションを構築しています.エンドユーザーがデータグリッドのトグル選択モードを使用できるようにしたい.IEは複数の行をクリックでき、クリックされた各アイテムはSelectedItemsプロパティに蓄積されます-行をクリックします行の選択が解除されます。別のスタックオーバーフローの質問でこのコードを見つけました:
<DataGrid.Resources>
<Style TargetType="{x:Type DataGridCell}">
<EventSetter Event="PreviewMouseLeftButtonDown" Handler="DoCheckRow" />
</Style>
</DataGrid.Resources>
public void DoCheckRow(object sender, MouseButtonEventArgs e)
{
DataGridCell cell = sender as DataGridCell;
if (cell != null && !cell.IsEditing)
{
DataGridRow row = VisualHelpers.TryFindParent<DataGridRow>(cell);
if (row != null)
{
row.IsSelected = !row.IsSelected;
e.Handled = true;
Debug.WriteLine(sender);
}
}
}
これは、トグル選択モードに関する限り、私が望むものを効果的に提供しますが、ボタンをCellTemplateとして追加するとe.Handled = true;
、イベントバブルを停止する上記のコードで設定しているため、クリックしてもボタンコマンドは起動されません。両方に対応できる方法はありますか?