AppBarButton.KeyboardAcceleratorTextOverride 屬性

定義

取得或設定字串,這個字串會覆寫與 鍵盤快速鍵相關聯的預設按鍵組合字元串。

顯示各種功能表項目鍵盤快速鍵的功能表範例
顯示各種功能表項目鍵盤快速鍵的功能表範例

public:
 property Platform::String ^ KeyboardAcceleratorTextOverride { Platform::String ^ get(); void set(Platform::String ^ value); };
winrt::hstring KeyboardAcceleratorTextOverride();

void KeyboardAcceleratorTextOverride(winrt::hstring value);
public string KeyboardAcceleratorTextOverride { get; set; }
var string = appBarButton.keyboardAcceleratorTextOverride;
appBarButton.keyboardAcceleratorTextOverride = string;
Public Property KeyboardAcceleratorTextOverride As String

屬性值

String

Platform::String

winrt::hstring

要取代預設按鍵組合字元串的字串。 預設值是 null。

針對沒有文字使用單一空格。

Windows 需求

裝置系列
Windows 10, version 1803 (已於 10.0.17134.0 引進)
API contract
Windows.Foundation.UniversalApiContract (已於 v6.0 引進)

備註

Windows 10 1703 版引進了鍵盤快速鍵。 不過,這些快捷方式未顯示其對應控制項的 UI。

從宣告KeyboardAccelerators Windows 10 1803 版開始,控制項預設會顯示對應的按鍵組合。

若系統無法偵測到已連結的鍵盤 (您可以透過 KeyboardPresent 屬性檢查),便不會顯示覆寫文字。

版本相容性

KeyboardAcceleratorTextOverride 屬性在 Windows 10 1803 版之前無法使用。 如果您的應用程式在 Microsoft Visual Studio 中的「最低平臺版本」設定小於此頁面稍後需求區塊中顯示的「引進版本」,您必須設計和測試您的應用程式以考慮此專案。 如需詳細資訊,請參閱 版本調適型程式碼

若要避免在舊版Windows 10上執行您的應用程式時發生例外狀況,請勿在 XAML 中設定此屬性,或在不執行執行時間檢查的情況下使用它。 此範例示範如何使用 ApiInformation 類別來檢查此屬性是否存在,再加以設定。

<CommandBar x:Name="commandBar1" Loaded="CommandBar_Loaded">
    <AppBarButton x:Name="appBarButtonCut" Icon="Cut" Label="Cut"/>
</CommandBar>
private void CommandBar_Loaded(object sender, RoutedEventArgs e)
{
    if (ApiInformation.IsPropertyPresent("Windows.UI.Xaml.Controls.AppBarButton", "KeyboardAcceleratorTextOverride"))
    {
        appBarButtonCut.KeyboardAcceleratorTextOverride = "Ctrl+C";
    }
}

適用於

另請參閱