EventManager.RegisterClassHandler Metodo
Definizione
Iscrive un gestore della classe per un particolare evento indirizzato.Registers a class handler for a particular routed event.
Overload
RegisterClassHandler(Type, RoutedEvent, Delegate) |
Iscrive un gestore della classe per un particolare evento indirizzato.Registers a class handler for a particular routed event. |
RegisterClassHandler(Type, RoutedEvent, Delegate, Boolean) |
Registra un gestore della classe per un particolare evento indirizzato, con l'opzione di gestire gli eventi in cui i dati degli eventi sono già contrassegnati come gestiti.Registers a class handler for a particular routed event, with the option to handle events where event data is already marked handled. |
RegisterClassHandler(Type, RoutedEvent, Delegate)
Iscrive un gestore della classe per un particolare evento indirizzato.Registers a class handler for a particular routed event.
public:
static void RegisterClassHandler(Type ^ classType, System::Windows::RoutedEvent ^ routedEvent, Delegate ^ handler);
public static void RegisterClassHandler (Type classType, System.Windows.RoutedEvent routedEvent, Delegate handler);
static member RegisterClassHandler : Type * System.Windows.RoutedEvent * Delegate -> unit
Public Shared Sub RegisterClassHandler (classType As Type, routedEvent As RoutedEvent, handler As Delegate)
Parametri
- classType
- Type
Il tipo della classe che dichiara la gestione della classe.The type of the class that is declaring class handling.
- routedEvent
- RoutedEvent
L'identificatore dell'evento indirizzato dell'evento da gestire.The routed event identifier of the event to handle.
- handler
- Delegate
Un riferimento all'implementazione del gestore di classe.A reference to the class handler implementation.
Esempio
Nell'esempio seguente viene aggiunto un gestore per la PreviewMouseLeftButtonDown chiamata a RegisterClassHandler .The following example adds a handler for PreviewMouseLeftButtonDown, calling RegisterClassHandler.
static MyEditContainer()
{
EventManager.RegisterClassHandler(typeof(MyEditContainer), PreviewMouseRightButtonDownEvent, new RoutedEventHandler(LocalOnMouseRightButtonDown));
}
internal static void LocalOnMouseRightButtonDown(object sender, RoutedEventArgs e)
{
MessageBox.Show("this is invoked before the On* class handler on UIElement");
//e.Handled = true; //uncommenting this would cause ONLY the subclass' class handler to respond
}
Shared Sub New()
EventManager.RegisterClassHandler(GetType(MyEditContainer), PreviewMouseRightButtonDownEvent, New RoutedEventHandler(AddressOf LocalOnMouseRightButtonDown))
End Sub
Friend Shared Sub LocalOnMouseRightButtonDown(ByVal sender As Object, ByVal e As RoutedEventArgs)
MessageBox.Show("this is invoked before the On* class handler on UIElement")
'e.Handled = True //uncommenting this would cause ONLY the subclass' class handler to respond
End Sub
Commenti
La gestione delle classi è una funzionalità disponibile per gli eventi indirizzati, inclusi gli eventi allegati implementati con il supporto degli eventi indirizzati.Class handling is a feature that is available for routed events, including attached events that are implemented with routed event backing. Un gestore di classi è simile a un gestore statico esistente per tutte le istanze della classe.A class handler is like a static handler that exists for all instances of the class. Poiché il gestore è statico, non è possibile modificare le proprietà dell'istanza direttamente con un gestore di classi, ma è possibile accedere alle istanze tramite il sender
parametro e/o i dati dell'evento.Because the handler is static, you cannot change instance properties directly with a class handler, but you can access instances through the sender
parameter and/or the event data.
I gestori di classi vengono richiamati prima di gestori di istanze.Class handlers are invoked before instance handlers. È possibile implementare un gestore di classi con il comportamento di contrassegnare l'evento come gestito.You can implement a class handler that has the behavior of marking the event as handled. I gestori di istanze per un evento gestito dalla classe, pertanto, non vengono richiamati, a meno che i gestori di istanze non si registrino specificamente per gli eventi gestiti.Therefore, instance handlers for a class-handled event are not invoked unless the instance handlers register specifically for handled events.
Molti degli WPFWPF eventi degli elementi di base forniscono metodi virtuali di gestione delle classi.Many of the WPFWPF base element events provide class handling virtual methods. Eseguendo l'override di questi metodi nelle classi che ereditano le classi di base, è possibile implementare la gestione della classe senza chiamare RegisterClassHandler nei costruttori statici.By overriding these methods in classes that inherit the base classes, you can implement class handling without calling RegisterClassHandler in static constructors. Questi metodi di gestione delle classi esistono in genere per gli eventi di input e hanno nomi che iniziano con "on" e terminano con il nome dell'evento gestito dalla classe.These class handling methods typically exist for input events and have names that start with "On" and end with the name of the event being class handled.
Per ulteriori informazioni sulla gestione delle classi, vedere contrassegno degli eventi indirizzati come gestiti e gestione delle classi.For more information about class handling, see Marking Routed Events as Handled, and Class Handling.
Utilizzando questa firma, i gestori classi verranno registrati per richiamare solo in risposta a eventi non gestiti.Using this signature, class handlers will be registered to invoke only in response to unhandled events. È anche possibile registrare i gestori di classi per richiamare anche se gli argomenti dell'evento sono contrassegnati come gestiti, usando la RegisterClassHandler(Type, RoutedEvent, Delegate, Boolean) firma, con handledEventsToo
impostato su true
.You can also register class handlers to invoke even if the event arguments are marked handled, by using the RegisterClassHandler(Type, RoutedEvent, Delegate, Boolean) signature, with handledEventsToo
set to true
.
Si applica a
RegisterClassHandler(Type, RoutedEvent, Delegate, Boolean)
Registra un gestore della classe per un particolare evento indirizzato, con l'opzione di gestire gli eventi in cui i dati degli eventi sono già contrassegnati come gestiti.Registers a class handler for a particular routed event, with the option to handle events where event data is already marked handled.
public:
static void RegisterClassHandler(Type ^ classType, System::Windows::RoutedEvent ^ routedEvent, Delegate ^ handler, bool handledEventsToo);
public static void RegisterClassHandler (Type classType, System.Windows.RoutedEvent routedEvent, Delegate handler, bool handledEventsToo);
static member RegisterClassHandler : Type * System.Windows.RoutedEvent * Delegate * bool -> unit
Public Shared Sub RegisterClassHandler (classType As Type, routedEvent As RoutedEvent, handler As Delegate, handledEventsToo As Boolean)
Parametri
- classType
- Type
Il tipo della classe che dichiara la gestione della classe.The type of the class that is declaring class handling.
- routedEvent
- RoutedEvent
L'identificatore dell'evento indirizzato dell'evento da gestire.The routed event identifier of the event to handle.
- handler
- Delegate
Un riferimento all'implementazione del gestore di classe.A reference to the class handler implementation.
- handledEventsToo
- Boolean
true
per richiamare questo gestore della classe anche se gli argomenti dell'evento indirizzato sono stati contrassegnati come gestiti; false
per mantenere il comportamento predefinito di non richiamare il gestore su qualsiasi evento contrassegnato come gestito.true
to invoke this class handler even if arguments of the routed event have been marked as handled; false
to retain the default behavior of not invoking the handler on any marked-handled event.
Commenti
La gestione delle classi è una funzionalità disponibile per gli eventi indirizzati, inclusi gli eventi allegati implementati con il supporto degli eventi indirizzati.Class handling is a feature that is available for routed events, including attached events that are implemented with routed event backing. Un gestore di classi è simile a un gestore statico esistente per tutte le istanze della classe.A class handler is like a static handler that exists for all instances of the class. Poiché il gestore è statico, non è possibile modificare le proprietà dell'istanza direttamente con un gestore di classi, ma è possibile accedere alle istanze tramite il sender
parametro e/o i dati dell'evento.Because the handler is static, you cannot change instance properties directly with a class handler, but you can access instances through the sender
parameter and/or the event data.
I gestori di classi vengono richiamati prima di gestori di istanze.Class handlers are invoked before instance handlers. È possibile implementare un gestore di classi con il comportamento di contrassegnare l'evento come gestito.You can implement a class handler that has the behavior of marking the event as handled. I gestori di istanze per un evento gestito dalla classe, pertanto, non vengono richiamati, a meno che i gestori di istanze non si registrino specificamente per gli eventi gestiti.Therefore, instance handlers for a class-handled event are not invoked unless the instance handlers register specifically for handled events.
Molti degli WPFWPF eventi degli elementi di base forniscono metodi virtuali di gestione delle classi.Many of the WPFWPF base element events provide class handling virtual methods. Eseguendo l'override di questi metodi nelle classi che ereditano le classi di base, è possibile implementare la gestione della classe senza chiamare RegisterClassHandler nei costruttori statici.By overriding these methods in classes that inherit the base classes, you can implement class handling without calling RegisterClassHandler in static constructors. Questi metodi di gestione delle classi esistono in genere per gli eventi di input e hanno nomi che iniziano con "on" e terminano con il nome dell'evento gestito dalla classe.These class handling methods typically exist for input events and have names that start with "On" and end with the name of the event being class handled.
Per ulteriori informazioni sulla gestione delle classi, vedere contrassegno degli eventi indirizzati come gestiti e gestione delle classi.For more information about class handling, see Marking Routed Events as Handled, and Class Handling.
Utilizzando questa firma, è possibile registrare i gestori classi per richiamare in caso di eventi gestiti, impostando su handledEventsToo
true
.Using this signature, class handlers can be registered to invoke upon handled events, by setting handledEventsToo
set to true
. In genere, è consigliabile eseguire questa operazione solo se si verifica un problema di gestione noto che si sta tentando di risolvere, ad esempio la gestione del sistema di input dagli eventi di mouse o tastiera.Generally, you should do this only if there is a known handling issue you are trying to work around, such as input system handling from mouse or keyboard events.