CanExecuteRoutedEventArgs 類別

定義

CanExecutePreviewCanExecute 路由事件提供資料。Provides data for the CanExecute and PreviewCanExecute routed events.

public ref class CanExecuteRoutedEventArgs sealed : System::Windows::RoutedEventArgs
public sealed class CanExecuteRoutedEventArgs : System.Windows.RoutedEventArgs
type CanExecuteRoutedEventArgs = class
    inherit RoutedEventArgs
Public NotInheritable Class CanExecuteRoutedEventArgs
Inherits RoutedEventArgs
繼承
CanExecuteRoutedEventArgs

範例

下列範例會建立CanExecuteRoutedEventHandler true , 只有在命令目標為控制項時, 才會傳回。The follow example creates a CanExecuteRoutedEventHandler that returns true only if the command target is a control. 首先, Source會轉換Control成。First, Source is cast to a Control. 如果Source CanExecute true是, 則會設定為, 否則會設定為falseControlIf Source is a Control, CanExecute is set to true; otherwise, it is set to 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 RoutedCommand呼叫方法, 以判斷命令是否可以或無法在目前的命令目標上執行。Typically, a command source, such a MenuItem, will call the CanExecute method on a RoutedCommand to determine if the command can or cannot execute on the current command target. 如果CanExecute從事件處理false程式將設定為, 命令來源將會自行停用。If CanExecute is set to false from an event handler, the command source will disable itself. 例如, 如果MenuItem是做為命令的命令來源, 而命令無法在目前的命令目標上執行, MenuItem則會變成灰色。For example, if a MenuItem is acting as the command source for a command and the command cannot execute on the current command target, then the MenuItem will gray itself out.

CanExecuteChanged命令執行的能力可能已變更時, 事件會通知命令來源。The CanExecuteChanged event notifies a command source when the ability of a command to execute may have changed.

屬性

CanExecute

取得或設定值,這個值會指出與這個事件相關聯的 RoutedCommand 是否可以在命令目標上執行。Gets or sets a value that indicates whether the RoutedCommand associated with this event can be executed on the command target.

Command

取得與這個事件相關聯的命令。Gets the command associated with this event.

ContinueRouting

判斷叫用命令的輸入路由事件是否應繼續透過元素樹狀結構路由。Determines whether the input routed event that invoked the command should continue to route through the element tree.

Handled

取得或設定值,這個值表示路由事件在傳送路由時之事件處理的目前狀態。Gets or sets a value that indicates the present state of the event handling for a routed event as it travels the route.

(繼承來源 RoutedEventArgs)
OriginalSource

在父類別進行任何可能的 Source 調整之前,取得純點擊測試所判定的原始報告來源。Gets the original reporting source as determined by pure hit testing, before any possible Source adjustment by a parent class.

(繼承來源 RoutedEventArgs)
Parameter

取得命令特有的資料。Gets the command specific data.

RoutedEvent

取得或設定與這個 RoutedEventArgs 執行個體相關聯的 RoutedEventGets or sets the RoutedEvent associated with this RoutedEventArgs instance.

(繼承來源 RoutedEventArgs)
Source

取得或設定引發事件之物件的參考。Gets or sets a reference to the object that raised the event.

(繼承來源 RoutedEventArgs)

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(繼承來源 Object)
GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)
InvokeEventHandler(Delegate, Object)

在衍生類別中覆寫時,提供以特定類型方式叫用事件處理常式的方式,這可透過基底實作來提高效率。When overridden in a derived class, provides a way to invoke event handlers in a type-specific way, which can increase efficiency over the base implementation.

(繼承來源 RoutedEventArgs)
MemberwiseClone()

建立目前 Object 的淺層複製。Creates a shallow copy of the current Object.

(繼承來源 Object)
OnSetSource(Object)

在衍生類別中覆寫時,每當執行個體的 Source 屬性值變更,便會提供通知回呼進入點。When overridden in a derived class, provides a notification callback entry point whenever the value of the Source property of an instance changes.

(繼承來源 RoutedEventArgs)
ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(繼承來源 Object)

適用於

另請參閱