CanExecuteRoutedEventArgs.CanExecute プロパティ
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
このイベントに関連付けられている 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にキャストされます。
Controlの場合、CanExecuteは 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やButtonなどの多くのコマンド ソースは、CanExecuteがfalseされると無効になり、CanExecuteがtrueされると有効になります。