Есть UserControl
, в котором, помимо прочего, есть DataGrid
.
Нужно извне привязать команду на Enter так:
<myControls:ProductsDataGrid.InputBindings>
<KeyBinding Key="Enter"
Command="{Binding OpenProductCommand}"
CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type myControls:ProductsDataGrid}}, Path=SelectedItem}" />
</myControls:ProductsDataGrid.InputBindings>
Проблема в том, что DataGrid
обрабатывает нажатие Enter по-своему и просто сдвигает выделение с текущей строки на следующую.
Если сменить клавишу, то все работает как надо.
Как добиться нужного поведения?
Если в DataGrid
биндить хоткеи таким образом, то все работает, но решение ненадежное.
<DataGrid.InputBindings>
<KeyBinding Key="Enter"
Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:ProductsDataGrid}}, Path=InputBindings[0].Command}"
CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:ProductsDataGrid}}, Path=InputBindings[0].CommandParameter}" />
</DataGrid.InputBindings>
Если в DataGrid биндить хоткеи таким образом, то все работает, но решение ненадежное.
Чем оно не надежное?