XamlUICommand Class

Definition

Provides a base class for defining the command behavior of an interactive UI element that performs an action when invoked (such as sending an email, deleting an item, or submitting a form).

Equivalent WinUI class: Microsoft.UI.Xaml.Input.XamlUICommand.

/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 458752)]
/// [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(Windows.Foundation.UniversalApiContract), 458752)]
[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
Inheritance
XamlUICommand
Derived
Attributes
Implements

Windows 10 requirements

Device family
Windows 10, version 1809 (introduced in 10.0.17763.0)
API contract
Windows.Foundation.UniversalApiContract (introduced in v7.0)

Examples

Tip

For more info, design guidance, and code examples, see Command design basics.

If you have the XAML Controls Gallery app installed, click here to open the app and see the StandardUICommand in action.

Remarks

Implements the ICommand interface (@"Windows.UI.Xaml.Input.ICommand?text=Windows.UI.Xaml.Input.ICommand" for C++ or System.Windows.Input.ICommand for C#), adding various UI properties, methods, and events.

XamlUICommand derived classes

XamlUICommand is the parent class for StandardUICommand, which exposes a set of standard platform commands with pre-defined properties.

For a basic commanding example see the Button control, which is designed to make something happen when a user clicks it.

There are two ways to process a Button command (controls with a Command property support similar functionality):

  • Handle the Click event
  • Bind the Command property to an ICommand implementation that describes the command logic

XamlUICommand lets you specify UI through the control binding, such as an icon, label, description, and keyboard shortcuts (both an access key and a keyboard accelerator), without setting the individual properties.

Constructors

XamlUICommand()

Initializes a new instance of the XamlUICommand class.

Equivalent WinUI constructor: Microsoft.UI.Xaml.Input.XamlUICommand.XamlUICommand.

Properties

AccessKey

Gets or sets the access key (mnemonic) for this element.

Equivalent WinUI property: Microsoft.UI.Xaml.Input.XamlUICommand.AccessKey.

AccessKeyProperty

Identifies the AccessKey dependency property.

Equivalent WinUI property: Microsoft.UI.Xaml.Input.XamlUICommand.AccessKeyProperty.

Command

Gets or sets the command behavior of an interactive UI element that performs an action when invoked, such as sending an email, deleting an item, or submitting a form.

Equivalent WinUI property: Microsoft.UI.Xaml.Input.XamlUICommand.Command.

CommandProperty

Identifies the Command dependency property.

Equivalent WinUI property: Microsoft.UI.Xaml.Input.XamlUICommand.CommandProperty.

Description

Gets or sets a description for this element.

Equivalent WinUI property: Microsoft.UI.Xaml.Input.XamlUICommand.Description.

DescriptionProperty

Identifies the Description dependency property.

Equivalent WinUI property: Microsoft.UI.Xaml.Input.XamlUICommand.DescriptionProperty.

Dispatcher

Gets the CoreDispatcher that this object is associated with. The CoreDispatcher represents a facility that can access the DependencyObject on the UI thread even if the code is initiated by a non-UI thread.

Equivalent WinUI property: Microsoft.UI.Xaml.DependencyObject.Dispatcher.

(Inherited from DependencyObject)
IconSource

Gets or sets a glyph from the Segoe MDL2 Assets font for this element.

Equivalent WinUI property: Microsoft.UI.Xaml.Input.XamlUICommand.IconSource.

IconSourceProperty

Identifies the IconSource dependency property.

Equivalent WinUI property: Microsoft.UI.Xaml.Input.XamlUICommand.IconSourceProperty.

KeyboardAccelerators

Gets or sets the collection of key combinations for this element that invoke an action using the keyboard.

Equivalent WinUI property: Microsoft.UI.Xaml.Input.XamlUICommand.KeyboardAccelerators.

KeyboardAcceleratorsProperty

Identifies the KeyboardAccelerators dependency property.

Equivalent WinUI property: Microsoft.UI.Xaml.Input.XamlUICommand.KeyboardAcceleratorsProperty.

Label

Gets or sets the label for this element.

Equivalent WinUI property: Microsoft.UI.Xaml.Input.XamlUICommand.Label.

LabelProperty

Identifies the Label dependency property.

Equivalent WinUI property: Microsoft.UI.Xaml.Input.XamlUICommand.LabelProperty.

Methods

CanExecute(Object)

Retrieves whether the command can execute in its current state.

Equivalent WinUI method: Microsoft.UI.Xaml.Input.XamlUICommand.CanExecute.

ClearValue(DependencyProperty)

Clears the local value of a dependency property.

Equivalent WinUI method: Microsoft.UI.Xaml.DependencyObject.ClearValue.

(Inherited from DependencyObject)
Execute(Object)

Invokes the command.

Equivalent WinUI method: Microsoft.UI.Xaml.Input.XamlUICommand.Execute.

GetAnimationBaseValue(DependencyProperty)

Returns any base value established for a dependency property, which would apply in cases where an animation is not active.

Equivalent WinUI method: Microsoft.UI.Xaml.DependencyObject.GetAnimationBaseValue.

(Inherited from DependencyObject)
GetValue(DependencyProperty)

Returns the current effective value of a dependency property from a DependencyObject.

Equivalent WinUI method: Microsoft.UI.Xaml.DependencyObject.GetValue.

(Inherited from DependencyObject)
NotifyCanExecuteChanged()

Notifies the system that the command state has changed.

Equivalent WinUI method: Microsoft.UI.Xaml.Input.XamlUICommand.NotifyCanExecuteChanged.

ReadLocalValue(DependencyProperty)

Returns the local value of a dependency property, if a local value is set.

Equivalent WinUI method: Microsoft.UI.Xaml.DependencyObject.ReadLocalValue.

(Inherited from DependencyObject)
RegisterPropertyChangedCallback(DependencyProperty, DependencyPropertyChangedCallback)

Registers a notification function for listening to changes to a specific DependencyProperty on this DependencyObject instance.

Equivalent WinUI method: Microsoft.UI.Xaml.DependencyObject.RegisterPropertyChangedCallback.

(Inherited from DependencyObject)
SetValue(DependencyProperty, Object)

Sets the local value of a dependency property on a DependencyObject.

Equivalent WinUI method: Microsoft.UI.Xaml.DependencyObject.SetValue.

(Inherited from DependencyObject)
UnregisterPropertyChangedCallback(DependencyProperty, Int64)

Cancels a change notification that was previously registered by calling RegisterPropertyChangedCallback.

Equivalent WinUI method: Microsoft.UI.Xaml.DependencyObject.UnregisterPropertyChangedCallback.

(Inherited from DependencyObject)

Events

CanExecuteChanged

Occurs whenever something happens that affects whether the command can execute.

Equivalent WinUI event: Microsoft.UI.Xaml.Input.XamlUICommand.CanExecuteChanged.

CanExecuteRequested

Occurs when a CanExecute call is made.

Equivalent WinUI event: Microsoft.UI.Xaml.Input.XamlUICommand.CanExecuteRequested.

ExecuteRequested

Occurs when an Execute call is made.

Equivalent WinUI event: Microsoft.UI.Xaml.Input.XamlUICommand.ExecuteRequested.

Applies to

See also