0
我需要爲幾個功能提供訪問快捷鍵,例如保存。爲此,我已經開始處理我的根對象的KeyUp事件,它是一個名爲LayoutRoot的網格(通常在Silverlight UserControl或Page中默認創建)。Silverlight訪問快捷鍵
我使用的MVVM模式,但爲了這個,我已經添加的代碼後面的代碼本身(這是UI交互,從而看起來OK):
private void LayoutRoot_KeyUp(object sender, KeyEventArgs e)
{
switch (e.Key)
{
case Key.S:
if ((Keyboard.Modifiers & ModifierKeys.Windows) == ModifierKeys.Windows)
{
e.Handled = true;
// save
}
break;
case Key.C:
if ((Keyboard.Modifiers & ModifierKeys.Windows) == ModifierKeys.Windows)
{
e.Handled = true;
// clear fields
}
break;
}
}
我已經使用了Windows鍵,因爲有就我所知,瀏覽器中沒有使用它的快捷方式。
我使用Command在Save按鈕上實現了Save功能,因此保留了MVVM模式。例如。
public RelayCommand CommandSavePtr { get; private set; }
CommandSavePtr = new RelayCommand(OnSavePtr);
private void OnSavePtr()
{
....
在XAML: -
<Button x:Name="SavePtrButton"
Command="{Binding CommandSavePtr}"
Style="{StaticResource StandardButtonStyle}"
IsEnabled="{Binding Ptr.HasErrors, Converter={StaticResource NotOperatorValueConverter}}">
<StackPanel Orientation="Horizontal">
<Image Source="/G4SPrisonerEscorting_ResourceDictionaries;component/images/accept.png" Style="{StaticResource SubPanelIconStyle}"/>
<TextBlock Text="Save"/>
</StackPanel>
</Button>
我現在的問題是,我不知道如何從我上面的KeyUp事件的視圖模型通信以執行點擊時所perfomed相同保存功能保存按鈕。
任何人都可以指向正確的方向。
順便說一句,我正在使用GalaSoft的MVVM光做指揮。