我已经创建了一点OKCancelControl
,我想在用户按下Enter
或时绑定一个命令Escape
这是 XAML
<UserControl.InputBindings>
<KeyBinding Key="Enter"
Command="{Binding ElementName=this, Path=OkCommand, UpdateSourceTrigger=PropertyChanged}"/>
<KeyBinding Key="Escape"
Command="iw:InnerWindow.CancelCommand"/>
</UserControl.InputBindings>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Border Grid.Column="0"
Style="{StaticResource BorderStyle}">
<Button Content="{Binding ElementName=this, Path=ButtonName, UpdateSourceTrigger=PropertyChanged}"
Command="{Binding ElementName=this, Path=OkCommand, UpdateSourceTrigger=PropertyChanged}"/>
</Border>
<Border Grid.Column="1"
Style="{StaticResource BorderStyle}">
<Button Content="{Binding Source={x:Static Member=t:BaseText.Cancel}}"
Command="iw:InnerWindow.CancelCommand" />
</Border>
</Grid>
但是只有当我的注意力在我的情况下不好时KeyBinding
才会处理。UserControl
我想找到一种 MVVM 或 XAML 方式(如果可能的话)让父母“听”用户按键。
先感谢您 ;)