UIElement.CommandBindings UIElement.CommandBindings UIElement.CommandBindings UIElement.CommandBindings Property

定义

获取与此元素关联的 CommandBinding 对象的集合。Gets a collection of CommandBinding objects associated with this element. CommandBinding 为此元素启用命令处理,并声明命令、命令的事件和由此元素附加的处理程序之间的链接。A CommandBinding enables command handling for this element, and declares the linkage between a command, its events, and the handlers attached by this element.

public:
 property System::Windows::Input::CommandBindingCollection ^ CommandBindings { System::Windows::Input::CommandBindingCollection ^ get(); };
public System.Windows.Input.CommandBindingCollection CommandBindings { get; }
member this.CommandBindings : System.Windows.Input.CommandBindingCollection
Public ReadOnly Property CommandBindings As CommandBindingCollection

属性值

示例

下面的示例添加CommandBinding到使用标记的窗口。The following example adds a CommandBinding to a window using markup. 请注意,在XAMLXAML,则CommandBindingCollection不为元素; 标记中声明的集合对象将该属性会采用,类型推断并填充一个或多个具有的属性元素CommandBinding元素:Note that in XAMLXAML, the CommandBindingCollection is not declared in the markup as an element; the collection object is inferred by the type that the property takes, and you populate the property element with one or more CommandBinding elements:

<Window.CommandBindings>
  <CommandBinding Command="ApplicationCommands.Open"
                  Executed="OpenCmdExecuted"
                  CanExecute="OpenCmdCanExecute"/>
</Window.CommandBindings>

有关详细信息XAMLXAML语法的集合,请参见XAML 语法详述For more information about the XAMLXAML syntax for collections, see XAML Syntax In Detail.

下面的示例执行在代码中实质上是相同的操作:The following example does essentially the same thing in code:

// Creating CommandBinding and attaching an Executed and CanExecute handler
CommandBinding OpenCmdBinding = new CommandBinding(
    ApplicationCommands.Open,
    OpenCmdExecuted,
    OpenCmdCanExecute);

this.CommandBindings.Add(OpenCmdBinding);
' Creating CommandBinding and attaching an Executed and CanExecute handler
Dim OpenCmdBinding As New CommandBinding(ApplicationCommands.Open, AddressOf OpenCmdExecuted, AddressOf OpenCmdCanExecute)

Me.CommandBindings.Add(OpenCmdBinding)

注解

另一种典型的方法来填充CommandBindings集合是使用CommandManager方法以编程方式。Another typical way to populate the CommandBindings collection is to use CommandManager methods programmatically.

XAML 属性元素用法XAML Property Element Usage

<object>  
  <object.CommandBindings>  
    oneOrMoreCommandBindings  
  </object.CommandBindings>  
</object>  

XAML 值XAML Values

oneOrMoreCommandBindingsoneOrMoreCommandBindings
一个或多个CommandBinding元素。One or more CommandBinding elements. 其中每项功能都应有Command属性设置为已知命令和属性设置为CanExecuteExecuted的处理程序实现。Each of these should have a Command attribute set to a known command, and attributes set for the CanExecute and Executed handler implementations. 有关详细信息,请参阅 CommandBindingFor more information see CommandBinding.

适用于

另请参阅