(5) C# 路由事件

 一、路由事件

1.定义、注册、封装路由

路由事件和依赖属性的定义类似

    public abstract class ButtonBase : ContentControl
    {
        public static readonly RoutedEvent ClickEvent;

        static ButtonBase()
        {
            ClickEvent = EventManager.RegisterRoutedEvent("Click", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(ButtonBase));
        }

        public event RoutedEventHandler Click
        {
            add
            {
                AddHandler(ClickEvent, value);
            }
            remove
            {
                RemoveHandler(ClickEvent, value);
            }
        }
    }

路由事件封装成普通都能访问的事件 add 和remove

 

2.共享路由

 

posted @ 2019-08-22 20:35  富坚老贼  阅读(807)  评论(0编辑  收藏  举报