Note that there are some explanatory texts on larger screens.

plurals
  1. POSilverlight Access Key Shortcuts
    text
    copied!<p>I need to provide access key shortcut for several functions such as Save. To do this I have started by handling the KeyUp event of my root object which is a Grid called LayoutRoot (typically created as default in a Silverlight UserControl or Page).</p> <p>I am using an MVVM pattern but for this I have added code in the code behind as such (this is UI interaction so it seems OK):</p> <pre><code> private void LayoutRoot_KeyUp(object sender, KeyEventArgs e) { switch (e.Key) { case Key.S: if ((Keyboard.Modifiers &amp; ModifierKeys.Windows) == ModifierKeys.Windows) { e.Handled = true; // save } break; case Key.C: if ((Keyboard.Modifiers &amp; ModifierKeys.Windows) == ModifierKeys.Windows) { e.Handled = true; // clear fields } break; } } </code></pre> <p>I have used the Windows key because there are no shorcuts in the browser that use it as far as I know.</p> <p>I implement the Save functionality on the Save button using a Command, therefore maintaining the MVVM pattern. E.g.</p> <pre><code>public RelayCommand CommandSavePtr { get; private set; } CommandSavePtr = new RelayCommand(OnSavePtr); private void OnSavePtr() { .... </code></pre> <p>In XAML: - </p> <pre><code> &lt;Button x:Name="SavePtrButton" Command="{Binding CommandSavePtr}" Style="{StaticResource StandardButtonStyle}" IsEnabled="{Binding Ptr.HasErrors, Converter={StaticResource NotOperatorValueConverter}}"&gt; &lt;StackPanel Orientation="Horizontal"&gt; &lt;Image Source="/G4SPrisonerEscorting_ResourceDictionaries;component/images/accept.png" Style="{StaticResource SubPanelIconStyle}"/&gt; &lt;TextBlock Text="Save"/&gt; &lt;/StackPanel&gt; &lt;/Button&gt; </code></pre> <p>My problem now is that I don't know how to communicate to the ViewModel from my above KeyUp event to perform the same Save function that is perfomed when clicking the Save button.</p> <p>Could anyone point me in the right direction.</p> <p>BTW I am using GalaSoft's MVVM Light to do the Commanding.</p>
 

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