다음을 통해 공유


CommandManager.AddCanExecuteHandler 메서드

정의

지정된 CanExecuteRoutedEventHandler를 지정된 요소에 연결합니다.

public:
 static void AddCanExecuteHandler(System::Windows::UIElement ^ element, System::Windows::Input::CanExecuteRoutedEventHandler ^ handler);
public static void AddCanExecuteHandler (System.Windows.UIElement element, System.Windows.Input.CanExecuteRoutedEventHandler handler);
static member AddCanExecuteHandler : System.Windows.UIElement * System.Windows.Input.CanExecuteRoutedEventHandler -> unit
Public Shared Sub AddCanExecuteHandler (element As UIElement, handler As CanExecuteRoutedEventHandler)

매개 변수

element
UIElement

handler를 연결할 요소입니다.

handler
CanExecuteRoutedEventHandler

실행 가능 처리기입니다.

예외

element 또는 handlernull인 경우

예제

다음 예에서는 CanExecuteRoutedEventHandlerExecutedRoutedEventHandler 에 연결을 Button 에 대 한 명령 소스는는 Help 명령입니다.

먼저 합니다 Button 만들어지고 연결 된는 Help 명령입니다.

<Button Command="ApplicationCommands.Help"
        Name="helpButton">Help</Button>

다음으로, CanExecuteRoutedEventHandlerExecutedRoutedEventHandler를 만듭니다.

private void HelpCmdExecuted(object sender, ExecutedRoutedEventArgs e)
{
    // OpenHelpFile opens the help file
    OpenHelpFile();
}
Private Sub HelpCmdExecuted(ByVal sender As Object, ByVal e As ExecutedRoutedEventArgs)
    ' OpenHelpFile opens the help file
    OpenHelpFile()
End Sub
private void HelpCmdCanExecute(object sender, CanExecuteRoutedEventArgs e)
{
    // HelpFilesExists() determines if the help file exists
    if (HelpFileExists() == true)
    {
        e.CanExecute = true;
    }
    else
    {
        e.CanExecute = false;
    }
}
Private Sub HelpCmdCanExecute(ByVal sender As Object, ByVal e As CanExecuteRoutedEventArgs)
    ' HelpFilesExists() determines if the help file exists
    If HelpFileExists() = True Then
        e.CanExecute = True
    Else
        e.CanExecute = False
    End If
End Sub

처리기에 연결 된 마지막으로, 및를 Button 를 사용 하는 AddCanExecuteHandlerAddExecutedHandler.

CommandManager.AddExecutedHandler(helpButton, HelpCmdExecuted);
CommandManager.AddCanExecuteHandler(helpButton, HelpCmdCanExecute);
CommandManager.AddExecutedHandler(helpButton, AddressOf HelpCmdExecuted)
CommandManager.AddCanExecuteHandler(helpButton, AddressOf HelpCmdCanExecute)

적용 대상

추가 정보