CommandBinding.CanExecute Evento

Definición

Se produce cuando el comando asociado a este CommandBinding inicia una comprobación para determinar si el comando se puede ejecutar en el destino del comando.Occurs when the command associated with this CommandBinding initiates a check to determine whether the command can be executed on the command target.

public:
 event System::Windows::Input::CanExecuteRoutedEventHandler ^ CanExecute;
public event System.Windows.Input.CanExecuteRoutedEventHandler CanExecute;
member this.CanExecute : System.Windows.Input.CanExecuteRoutedEventHandler 
Public Event CanExecute As CanExecuteRoutedEventHandler 

Ejemplos

En el ejemplo siguiente se CommandBinding crea un que ExecutedRoutedEventHandler asigna un CanExecuteRoutedEventArgs Open y un controlador al comando.The following example creates a CommandBinding that maps an ExecutedRoutedEventHandler and a CanExecuteRoutedEventArgs handler to the Open command.

<Window.CommandBindings>
  <CommandBinding Command="ApplicationCommands.Open"
                  Executed="OpenCmdExecuted"
                  CanExecute="OpenCmdCanExecute"/>
</Window.CommandBindings>
// 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)

A continuación se muestra CanExecuteRoutedEventHandler la que CanExecute establece trueen.The following shows the CanExecuteRoutedEventHandler which sets CanExecute to true.

void OpenCmdCanExecute(object sender, CanExecuteRoutedEventArgs e)
{
    e.CanExecute = true;
}
Private Sub OpenCmdCanExecute(ByVal sender As Object, ByVal e As CanExecuteRoutedEventArgs)
    e.CanExecute = True
End Sub

Comentarios

Cuando se llama al PreviewCanExecute método en, el evento se genera en el destino del comando. CanExecute RoutedCommandWhen the CanExecute method on a RoutedCommand is called, the PreviewCanExecute event is raised on the command target. Si no se controla el evento, se CanExecute genera el evento.If the event is not handled, the CanExecute event is raised. Si el destino del comando tiene CommandBinding un para el comando, CanExecute CommandBinding se llama al controlador de.If the command target has a CommandBinding for the command, the CanExecute handler for that CommandBinding is called. Si el destino del comando no tiene un CommandBinding para el comando, el CanExecute evento propaga el árbol de elementos buscando un elemento que tiene un CommandBinding asociado al comando.If the command target does not have a CommandBinding for the command, the CanExecute event bubbles up the element tree searching for an element that has a CommandBinding associated with the command.

Información sobre eventos enrutadosRouted Event Information

Campo de identificadorIdentifier field CanExecuteEvent
Estrategia de enrutamientoRouting strategy PropagaciónBubbling
delegadoDelegate CanExecuteRoutedEventHandler

Se aplica a

Consulte también: