/// <summary>
/// 演示用的自定义控件
/// </summary>
public class ExtButton : Button
{
public ExtButton()
{
base .Click += ExtButton_Click;
}
private void ExtButton_Click( object sender, RoutedEventArgs e)
{
//定义传递参数
// RoutedPropertyChangedEventArgs<Object> args = new RoutedPropertyChangedEventArgs<Object>("1", "2", ControlLoadOverEvent);
RoutedEventArgs args2 = new RoutedEventArgs(ControlLoadOverEvent, this );
//引用自定义路由事件
this .RaiseEvent(args2);
}
/// <summary>
/// 声明路由事件
/// 参数:要注册的路由事件名称,路由事件的路由策略,事件处理程序的委托类型(可自定义),路由事件的所有者类类型
/// </summary>
public static readonly RoutedEvent ControlLoadOverEvent = EventManager.RegisterRoutedEvent( "ControlLoadOverEvent" , RoutingStrategy.Bubble, typeof (RoutedPropertyChangedEventArgs<Object>), typeof (ExtButton));
/// <summary>
/// 处理各种路由事件的方法
/// </summary>
public event RoutedEventHandler ControlLoadOver
{
//将路由事件添加路由事件处理程序
add { AddHandler(ControlLoadOverEvent, value); }
//从路由事件处理程序中移除路由事件
remove { RemoveHandler(ControlLoadOverEvent, value); }
}
}
|