Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This works for me (.Net 4.0)</p> <pre><code>&lt;UserControl&gt; &lt;UserControl.InputBindings&gt; &lt;KeyBinding Gesture="CTRL+C" Command="{Binding CancelCommand}" /&gt; &lt;KeyBinding Gesture="F5" Command="{Binding StartCommand}" /&gt; &lt;KeyBinding Gesture="CTRL+F5" Command="{Binding FreshStartCommand}" /&gt; &lt;KeyBinding Gesture="F10" Command="{Binding ContinueCommand}" /&gt; &lt;KeyBinding Gesture="F9" Command="{Binding RepeatCommand}" /&gt; &lt;KeyBinding Gesture="ALT+F4" Command="{Binding CloseCommand}" /&gt; &lt;KeyBinding Gesture="CTRL+N" Command="{Binding NewUUTCommand}" /&gt; &lt;/UserControl.InputBindings&gt; .... &lt;StackPanel DockPanel.Dock="Bottom" Orientation="Horizontal" HorizontalAlignment="Center"&gt; &lt;Button x:Name="BtnStart" Content="STARTEN" Command="{Binding StartCommand}"/&gt; &lt;Button Content="STOP" Command="{Binding StopCommand}"/&gt; &lt;/StackPanel&gt; .... &lt;FocusManager.FocusedElement&gt; &lt;Binding ElementName="BtnStart"/&gt; &lt;/FocusManager.FocusedElement&gt; &lt;/UserControl&gt; </code></pre> <p>The trick is to ensure that the focus is set into the UserControl. For me, this wasn't happening automatically. Once the focus is set then the KeyBinding works. (Note the focus is set right at the end as the element has to be defined first)</p> <p>For completeness, here is the ViewModel code.</p> <pre><code>public ICommand StartCommand { get { if (this._startCommand == null) { this._startCommand = new Mvvm.RelayCommand(parm =&gt; DoStart(), parm =&gt; DoCanStart()); } return this._startCommand; } } private bool DoCanStart() { return !IsRunning &amp;&amp; ReadyToRun; } private void DoStart() { log.Debug("Start test"); ... } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload