CanExecuteRoutedEventArgs.CanExecute 속성

정의

이 이벤트와 연결된 RoutedCommand를 명령 대상에서 실행할 수 있는지 여부를 나타내는 값을 가져오거나 설정합니다.

public:
 property bool CanExecute { bool get(); void set(bool value); };
public bool CanExecute { get; set; }
member this.CanExecute : bool with get, set
Public Property CanExecute As Boolean

속성 값

명령 대상에서 이벤트를 실행할 수 있으면 true이고, 그렇지 않으면 false입니다. 기본값은 false입니다.

예제

다음 예제에서는 명령 대상이 컨트롤인 경우에만 true를 반환하는 을 만듭니다 CanExecuteRoutedEventHandler . Source 먼저 이벤트 데이터가 로 Control캐스팅됩니다. 이 인 ControlCanExecute 경우 는 로 true설정되고, 그렇지 않으면 로 설정false됩니다.

// CanExecuteRoutedEventHandler that only returns true if
// the source is a control.
private void CanExecuteCustomCommand(object sender, 
    CanExecuteRoutedEventArgs e)
{
    Control target = e.Source as Control;
    
    if(target != null)
    {
        e.CanExecute = true;
    }
    else
    {
        e.CanExecute = false;
    }
}
' CanExecuteRoutedEventHandler that only returns true if
' the source is a control.
Private Sub CanExecuteCustomCommand(ByVal sender As Object, ByVal e As CanExecuteRoutedEventArgs)
    Dim target As Control = TryCast(e.Source, Control)

    If target IsNot Nothing Then
        e.CanExecute = True
    Else
        e.CanExecute = False
    End If
End Sub

설명

및 와 같은 MenuItem 많은 명령 원본은 가 인 경우 CanExecute 사용하지 않도록 설정되고 가 false 일 때 CanExecute 사용하도록 설정됩니다trueButton.

적용 대상

추가 정보