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

Definição

Obtém uma coleção de objetos CommandBinding associados a esse elemento.Gets a collection of CommandBinding objects associated with this element. Um CommandBinding permite a manipulação de comando desse elemento e declara a ligação entre um comando, seus eventos e os manipuladores anexados por esse 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 da propriedade

Exemplos

O exemplo a seguir adiciona CommandBinding um a uma janela usando marcação.The following example adds a CommandBinding to a window using markup. Observe que em XAMLXAML, o CommandBindingCollection não é declarado na marcação como um elemento; o objeto de coleção é inferido pelo tipo que a propriedade usa, e você preenche o elemento de propriedade com um ou mais 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 obter mais informações sobre XAMLXAML a sintaxe de coleções, consulte sintaxe XAML em detalhes.For more information about the XAMLXAML syntax for collections, see XAML Syntax In Detail.

O exemplo a seguir faz essencialmente a mesma coisa no 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)

Comentários

Outra maneira comum de popular a CommandBindings coleção é usar CommandManager métodos programaticamente.Another typical way to populate the CommandBindings collection is to use CommandManager methods programmatically.

Uso do elemento propriedade XAMLXAML Property Element Usage

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

Valores XAMLXAML Values

oneOrMoreCommandBindingsoneOrMoreCommandBindings
Um ou mais CommandBinding elementos.One or more CommandBinding elements. Cada um deles deve ter um Command atributo definido como um comando conhecido e os atributos definidos para as CanExecute implementações do manipulador e Executed .Each of these should have a Command attribute set to a known command, and attributes set for the CanExecute and Executed handler implementations. Para obter mais informações, consulte CommandBinding.For more information see CommandBinding.

Aplica-se a

Veja também