CommandBindingCollection.Add(CommandBinding) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Adds the specified CommandBinding to this CommandBindingCollection.
public:
int Add(System::Windows::Input::CommandBinding ^ commandBinding);
public int Add (System.Windows.Input.CommandBinding commandBinding);
member this.Add : System.Windows.Input.CommandBinding -> int
Public Function Add (commandBinding As CommandBinding) As Integer
Parameters
- commandBinding
- CommandBinding
The binding to add to the collection.
Returns
0, if the operation was successful (note that this is not the index of the added item).
Exceptions
commandBinding
is null.
Examples
The following example creates a CommandBinding and adds it to the CommandBindingCollection of a Window.
<Window x:Class="SDKSamples.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:custom="clr-namespace:SDKSamples"
Height="600" Width="800"
>
<Window.CommandBindings>
<CommandBinding Command="{x:Static custom:Window1.CustomRoutedCommand}"
Executed="ExecutedCustomCommand"
CanExecute="CanExecuteCustomCommand" />
</Window.CommandBindings>
CommandBinding customCommandBinding = new CommandBinding(
CustomRoutedCommand, ExecutedCustomCommand, CanExecuteCustomCommand);
// attach CommandBinding to root window
this.CommandBindings.Add(customCommandBinding);
Dim customCommandBinding As New CommandBinding(CustomRoutedCommand, AddressOf ExecutedCustomCommand, AddressOf CanExecuteCustomCommand)
' attach CommandBinding to root window
Me.CommandBindings.Add(customCommandBinding)
Applies to
See also
Συνεργαστείτε μαζί μας στο GitHub
Μπορείτε να βρείτε την πηγή για αυτό το περιεχόμενο στο GitHub, όπου μπορείτε επίσης να δημιουργήσετε και να εξετάσετε ζητήματα και αιτήματα έλξης. Για περισσότερες πληροφορίες, ανατρέξτε στον οδηγό συνεργατών.