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

Definición

Obtiene una colección de objetos CommandBinding asociados a este elemento.Gets a collection of CommandBinding objects associated with this element. CommandBinding habilita el control de comandos para este elemento y declara la vinculación entre un comando, sus eventos y los controladores asociados por este elemento.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

Valor de propiedad

Ejemplos

En el ejemplo siguiente se agrega un CommandBinding a una ventana mediante marcado.The following example adds a CommandBinding to a window using markup. Tenga en cuenta que en XAMLXAML, CommandBindingCollection no se ha declarado en el marcado como un elemento; el objeto de colección se deduce el tipo que toma la propiedad y rellenar el elemento de propiedad con uno o varios CommandBinding elementos: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>

Para obtener más información sobre la XAMLXAML sintaxis de colecciones, vea XAML detalles de la sintaxis.For more information about the XAMLXAML syntax for collections, see XAML Syntax In Detail.

El ejemplo siguiente hace básicamente lo mismo en el código: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)

Comentarios

Otra manera típica de rellenar la CommandBindings colección consiste en usar CommandManager métodos mediante programación.Another typical way to populate the CommandBindings collection is to use CommandManager methods programmatically.

Uso de elementos de propiedad XAMLXAML Property Element Usage

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

Valores XAMLXAML Values

oneOrMoreCommandBindingsoneOrMoreCommandBindings
Uno o más CommandBinding elementos.One or more CommandBinding elements. Cada uno de ellos debe tener un Command atributo establecido en un comando conocido, y los atributos establecidos para el CanExecute y Executed las implementaciones de controladores.Each of these should have a Command attribute set to a known command, and attributes set for the CanExecute and Executed handler implementations. Para obtener más información, vea CommandBinding.For more information see CommandBinding.

Se aplica a

Consulte también: