語言

XamlUICommand 類別

定義

提供一個基底類別,用以定義互動式 UI 元素的指令行為,該元素在呼叫時執行動作(例如發送電子郵件、刪除項目或提交表單)。

/// [Windows.Foundation.Metadata.ContractVersion(Microsoft.UI.Xaml.WinUIContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class XamlUICommand : DependencyObject, ICommand
[Windows.Foundation.Metadata.ContractVersion(typeof(Microsoft.UI.Xaml.WinUIContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public class XamlUICommand : DependencyObject, ICommand
Public Class XamlUICommand
Inherits DependencyObject
Implements ICommand
繼承
Object IInspectable DependencyObject XamlUICommand
衍生
屬性
實作

範例

Tip

欲了解更多資訊、設計指引及程式碼範例,請參閱指令基礎。

WinUI 3 Gallery 應用程式包含大部分 WinUI 3 控制項、特性和功能的互動式範例。 從 Microsoft Store 取得應用程式,或在 GitHub 上取得原始程式碼。

備註

實作介面ICommand(Microsoft.UI。適用於 C++ 或 System.Windows 的 Xaml.Input.ICommand。C# 的 Input.ICommand),新增各種 UI 屬性、方法與事件。

XamlUICommand 衍生類別

XamlUICommand 是 StandardUICommand 的父類別,該類別暴露一組具有預設屬性的標準平台指令。

基本的指令範例請參考 按鈕 控制,該控制項設計用於使用者點擊時發生某些動作。

處理 Button 指令有兩種方式(具有 Command 屬性的控制項支援類似功能):

  • 處理事件Click
  • 將屬性 Command 綁定到描述指令邏輯的 ICommand 實作

XamlUICommand 讓你可以透過控制鍵綁定來指定使用者介面,例如圖示、標籤、描述和鍵盤快捷鍵(包括存取鍵和鍵盤加速鍵),而不必設定個別屬性。

建構函式

名稱 Description
XamlUICommand()

初始化 XamlUICommand 類別的新實例。

屬性

名稱 Description
AccessKey

取得或設定此元素的存取鍵(助記鍵)。

AccessKeyProperty

識別 AccessKey 相依屬性。

Command

取得或設定互動式 UI 元素的指令行為,該元素在被呼叫時執行動作,例如發送電子郵件、刪除項目或提交表單。

CommandProperty

識別 指令 依賴屬性。

Description

取得或設定這個元素的描述。

DescriptionProperty

識別 描述相依 屬性。

Dispatcher

它總是在 Windows 應用程式 SDK 應用程式中回傳 null 。 改用 DispatcherQueue 。

(繼承來源 DependencyObject)
DispatcherQueue

得到 DispatcherQueue 這個物件所關聯的那個。 代表 DispatcherQueue 一個功能,即使程式碼是由非 UI 執行緒發起,也能存取 UI DependencyObject 執行緒。

(繼承來源 DependencyObject)
IconSource

從 Segoe MDL2 Assets 字型取得或設定這個元素的字形。

IconSourceProperty

識別 IconSource 依賴屬性。

KeyboardAccelerators

取得此元素的按鍵組合集合,用鍵盤呼叫動作。

KeyboardAcceleratorsProperty

識別 KeyboardAccelerators 相依屬性。

Label

取得或設定這個元素的標籤。

LabelProperty

識別 標籤相依 屬性。

方法

名稱 Description
CanExecute(Object)

取得指令是否能在當前狀態下執行。

ClearValue(DependencyProperty)

清除依賴性財產的局部價值。

(繼承來源 DependencyObject)
Execute(Object)

啟動指令。

GetAnimationBaseValue(DependencyProperty)

回傳任何為相依屬性建立的基礎值,適用於動畫未啟用時。

(繼承來源 DependencyObject)
GetValue(DependencyProperty)

回傳 DependencyObject 中相依屬性的當前有效值。

(繼承來源 DependencyObject)
NotifyCanExecuteChanged()

通知系統指令狀態已變更。

ReadLocalValue(DependencyProperty)

若設定了本地值,則回傳依賴性質的局部值。

(繼承來源 DependencyObject)
RegisterPropertyChangedCallback(DependencyProperty, DependencyPropertyChangedCallback)

註冊一個通知函式,用於監聽此 DependencyObject 實例中特定 DependencyProperty 的變更。

(繼承來源 DependencyObject)
SetValue(DependencyProperty, Object)

將相依屬性的局部值設定在 DependencyObject 上。

(繼承來源 DependencyObject)
UnregisterPropertyChangedCallback(DependencyProperty, Int64)

取消先前透過呼叫 RegisterPropertyChangedCallback 註冊的變更通知。

(繼承來源 DependencyObject)

事件

名稱 Description
CanExecuteChanged

每當發生影響指令是否能執行的事件時,就會出現這種情況。

CanExecuteRequested

當發出 CanExecute 呼叫時會發生。

ExecuteRequested

當 執行呼叫時 會發生。

適用於

另請參閱