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입니다.

예제

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

// 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

설명

와 같은 MenuItemButton많은 명령 원본은 있는 CanExecute 경우 false 비활성화되고 있는 경우 CanExecute 사용하도록 설정됩니다true.

적용 대상

추가 정보