2
我创建了一个小OKCancelControl
,我想绑定在用户按下Enter
或Escape
如何将UserControl的KeyBinding传递给它的父项?
这里的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方式(如果可能)让父母“听”用户键按下。
预先感谢您;)