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 CommandBinding agrega un a una ventana mediante el marcado.The following example adds a CommandBinding to a window using markup. Tenga en cuenta XAMLXAMLque en CommandBindingCollection , no se declara en el marcado como un elemento; el objeto de colección se deduce por el tipo que toma la propiedad y rellena el elemento de propiedad con uno o CommandBinding varios 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 XAMLXAML la sintaxis de las colecciones, vea la Sintaxis de XAML en detalle.For more information about the XAMLXAML syntax for collections, see XAML Syntax In Detail.

En el ejemplo siguiente se 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 forma habitual de rellenar la CommandBindings colección es 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 una de ellas debe tener Command un atributo establecido en un comando conocido y los atributos establecidos para CanExecute las Executed implementaciones del controlador y.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: