2012-07-19 38 views
7

WPF, klavye kısayollarını pencere düzeyinde kolayca InputBindings özelliğini kullanarak bir yöntemle bağlama olanağı sağlar. WinRT'de buna eşdeğer nedir? WinRT'deki yöntemlere klavye kısayollarını bağlamanın doğru yolu nedir?WinBB girişleri WinRT eşdeğeri nedir?

cevap

7

Klavye kısayolları here olarak tanımlanmıştır. Bence, access keys veya accelerator keys'u istiyorsun.

Erişim anahtarı, uygulamanızdaki bir UI parçasının kısayoludur. Erişim tuşları Alt tuşu artı bir harf tuşundan oluşur.

Bir hızlandırıcı tuşu, bir uygulama komutunun kısayoludur. Uygulamanız, tam olarak komuta karşılık gelen kullanıcı arayüzüne sahip olabilir veya olmayabilir. Hızlandırıcı tuşlar Ctrl tuşunun yanı sıra bir harf tuşundan oluşur.

Aşağıdaki örnek düğmeleri medya oynatma, durdurma için kısayol tuşları erişilebilir uygulanmasını gösterir ve durdurma:

<MediaElement x:Name="Movie" Source="sample.wmv" 
    AutoPlay="False" Width="320" Height="240"/> 

<StackPanel Orientation="Horizontal" HorizontalAlignment="Center"> 

    <Button x:Name="Play" Margin="1,2" 
    ToolTipService.ToolTip="shortcut key: Ctrl+P" 
    AutomationProperties.AccessKey="Control P"> 
    <TextBlock><Underline>P</Underline>lay</TextBlock> 
    </Button> 

    <Button x:Name="Pause" Margin="1,2" 
    ToolTipService.ToolTip="shortcut key: Ctrl+A" 
    AutomationProperties.AccessKey="Control A"> 
    <TextBlock>P<Underline>a</Underline>use</TextBlock> 
    </Button> 

    <Button x:Name="Stop" Margin="1,2" 
    ToolTipService.ToolTip="shortcut key: Ctrl+S" 
    AutomationProperties.AccessKey="Control S"> 
    <TextBlock><Underline>S</Underline>top</TextBlock> 
    </Button> 

</StackPanel> 

<object AutomationProperties.AcceleratorKey="ALT+F" /> 

Important: Setting AutomationProperties.AcceleratorKey or AutomationProperties.AccessKey doesn't enable keyboard functionality. It only reports to the UI Automation framework what keys should be used, so that such information can be passed on to users via assistive technologies. The implementation for key handling still needs to be done in code, not XAML. You will still need to attach handlers for KeyDown or KeyUp events on the relevant control in order to actually implement the keyboard shortcut behavior in your app. Also, the underline text decoration for an access key is not provided automatically. You must explicitly underline the text for the specific key in your mnemonic as inline Underline formatting if you wish to show underlined text in the UI.

için uygulama ayrıntıları için

bakınız @ Magiel cevabı şeylerin kod tarafı.

+0

Peki ya MouseBinding? StackOverflow sorusuna http://stackoverflow.com/a/7354984 bakın. –

+0

@ Stefano.net Ne demek istediğinden emin değilim. Fare bağlama hakkında ne dersiniz? – mydogisbox

+0

Fare olaylarını, örneğin bir dikdörtgen gibi doğrudan işlenmeyen nesnelere InputBinding (veya eşdeğeri) yoluyla ekleme. –

5

Önemli! Ayar OtomasyonuProperties.AcceleratorKey veya AutomationProperties.AccessKey, klavye işlevlerini etkinleştirmez. Sadece UI Otomasyon çerçevesine hangi anahtarların kullanılması gerektiğini bildirir, böylece bu tür bilgiler yardımcı teknolojiler aracılığıyla kullanıcılara aktarılabilir. Anahtar kullanımının hala XAML'de değil kodda yapılması gerekiyor.

protected override void OnNavigatedTo(NavigationEventArgs e) 
{ 
    // Set the input focus to ensure that keyboard events are raised. 
    this.Loaded += delegate { this.Focus(FocusState.Programmatic); }; 
} 

private void Grid_KeyUp(object sender, KeyRoutedEventArgs e) 
{ 
    if (e.Key == VirtualKey.Control) isCtrlKeyPressed = false; 
} 

private void Grid_KeyDown(object sender, KeyRoutedEventArgs e) 
{ 
    if (e.Key == VirtualKey.Control) isCtrlKeyPressed = true; 
    else if (isCtrlKeyPressed) 
    { 
     switch (e.Key) 
     { 
      case VirtualKey.P: DemoMovie.Play(); break; 
      case VirtualKey.A: DemoMovie.Pause(); break; 
      case VirtualKey.S: DemoMovie.Stop(); break; 
     } 
    } 
}