使用GetType注册自定义路由事件时有什么区别(RoutedEventHandler) 或GetType(RoutedEventArgs)??
ex1:
Public Shared ReadOnly TextChangedEvent As RoutedEvent = EventManager.RegisterRoutedEvent("TextChanged", _
RoutingStrategy.Bubble, GetType(RoutedEventArgs), GetType(MyCustomTextBlock))
ex2:
Public Shared ReadOnly TextChangedEvent As RoutedEvent = EventManager.RegisterRoutedEvent("TextChanged", _
RoutingStrategy.Bubble, GetType(RoutedEventHandler), GetType(MyCustomTextBlock))
答案 0 :(得分:0)
当您注册RoutedEvent时,您必须提供许多参数,包括委托类型。
来自MSDN
public static RoutedEvent RegisterRoutedEvent(
string name,
RoutingStrategy routingStrategy,
Type handlerType, // see note below.
Type ownerType )
<强> handlerType 强>
输入:System.Type
事件处理程序的类型。这必须是委托类型,不能为空。
选择类型
因此,您的第一个示例(ex1)使用了错误的类型。您没有传递EventArgs。而是传递委托类型。 .NET中有许多委托类型,但在这种情况下你应该使用一个来自RoutedEvent args的派生。