2012-07-19 18 views
7

डब्ल्यूपीएफ मुझे इनपुटबिंडिंग प्रॉपर्टी का उपयोग करके एक विधि में विंडो स्तर पर कीबोर्ड शॉर्टकट को आसानी से बांधने की अनुमति देता है। WinRT में इसके बराबर क्या है? WinRT में विधियों के लिए कीबोर्ड शॉर्टकट को बाध्य करने का सही तरीका क्या है?इनपुटबिंडिंग के WinRT समकक्ष क्या है?

उत्तर

7

कीबोर्ड शॉर्टकट का वर्णन here है। मुझे लगता है कि आप या तो access keys या accelerator keys चाहते हैं।

एक एक्सेस कुंजी आपके ऐप में यूआई के टुकड़े के लिए शॉर्टकट है। एक्सेस कुंजियों में Alt कुंजी प्लस एक अक्षर कुंजी शामिल है।

एक त्वरक कुंजी ऐप कमांड का शॉर्टकट है। आपके ऐप में यूआई हो या नहीं हो जो कि कमांड के अनुरूप है। त्वरक कुंजी में Ctrl कुंजी प्लस एक अक्षर कुंजी होती है।

निम्न उदाहरण मीडिया चलाना, रोकना के लिए शॉर्टकट कुंजियों की सुलभ कार्यान्वयन को दर्शाता है, और बटन बंद करो:

<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.

के लिए कार्यान्वयन विवरण के लिए देखें @ Magiel के जवाब चीजों का कोड-साइड।

+0

और माउस बाइंडिंग के बारे में क्या? StackOverflow प्रश्न http://stackoverflow.com/a/7354984 देखें। –

+0

@ Stefano.net मुझे यकीन नहीं है कि आपका क्या मतलब है। माउस बाध्यकारी के बारे में क्या? – mydogisbox

+0

ऑब्जेक्ट बाइंडिंग (या समतुल्य) के माध्यम से माउस ईवेंट को अटैचमेंट करने के लिए सीधे आयत की तरह नहीं संभालना। –

5

महत्वपूर्ण !! ऑटोमेशनप्रॉपर्टीज सेट करना। एक्सेलेरेटरकी या ऑटोमेशनप्रॉपर्टीज। एक्सेसकी कुंजीपटल कार्यक्षमता को सक्षम नहीं करता है। यह केवल यूआई ऑटोमेशन फ्रेमवर्क को रिपोर्ट करता है कि किन चाबियों का उपयोग किया जाना चाहिए, ताकि ऐसी जानकारी सहायक तकनीकों के माध्यम से उपयोगकर्ताओं को दी जा सके। कुंजी हैंडलिंग के लिए कार्यान्वयन अभी भी कोड में किया जाना चाहिए, एक्सएएमएल नहीं।

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; 
     } 
    } 
} 
संबंधित मुद्दे