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

Definizione

Ottiene un insieme di oggetti CommandBinding associati a questo elemento.Gets a collection of CommandBinding objects associated with this element. Un oggetto CommandBinding consente la gestione dei comandi per questo elemento e dichiara il collegamento tra un comando, i relativi eventi e i gestori associati da questo 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

Valore della proprietà

Esempi

Nell'esempio seguente viene aggiunto CommandBinding un oggetto a una finestra utilizzando il markup.The following example adds a CommandBinding to a window using markup. Si noti che XAMLXAMLin CommandBindingCollection non è dichiarato nel markup come elemento. l'oggetto raccolta viene dedotto dal tipo che la proprietà accetta e si popola l'elemento Property con uno o più CommandBinding elementi: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>

Per ulteriori informazioni sulla sintassi XAMLXAML per le raccolte, vedere sintassi XAML in dettaglio.For more information about the XAMLXAML syntax for collections, see XAML Syntax In Detail.

Nell'esempio seguente viene eseguita essenzialmente la stessa operazione nel codice: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)

Commenti

Un altro modo comune per popolare CommandBindings la raccolta consiste nell' CommandManager usare i metodi a livello di codice.Another typical way to populate the CommandBindings collection is to use CommandManager methods programmatically.

Utilizzo della sintassi XAML per elementi proprietàXAML Property Element Usage

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

Valori XAMLXAML Values

oneOrMoreCommandBindingsoneOrMoreCommandBindings
Uno o più CommandBinding elementi.One or more CommandBinding elements. Ognuno di questi deve avere un Command attributo impostato su un comando noto e gli attributi impostati per le CanExecute implementazioni del gestore 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. Per altre informazioni, vedere CommandBinding.For more information see CommandBinding.

Si applica a

Vedi anche