少し作成しましたが、ユーザーがまたは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 の方法 (可能であれば) を見つけたいと思います。
前もって感謝します ;)