WPF之定义路由事件 http://www.51zxw.net/study.asp?vip=8963801

9 篇文章 0 订阅
 
 [url= http://www.51zxw.net/study.asp?vip=8963801] 学IT必看,【经典】 【基础】 【进阶】 【实践 】 【成神】【超神】【返璞归真】
[/url]
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
namespace WPFRoutedEvent
{
    public class RoutedEventEx : Button
    {
        /// <summary>
        /// 定义路由事件
        /// </summary>
        public static readonly RoutedEvent ClickEvent;
 

        #region 路由事件类型  RoutingStrategy
        摘要:
             指示路由事件的路由
        //public enum RoutingStrategy
        //{
        //    // 摘要:
        //    //     路由事件使用隧道策略,以便事件实例通过树向下路由(从根到源元素)。
        //    Tunnel = 0,
        //    //
        //    // 摘要:
        //    //     路由事件使用冒泡策略,以便事件实例通过树向上路由(从事件元素到根)。
        //    Bubble = 1,
        //    //
        //    // 摘要:
        //    //     路由事件不通过元素树路由,但支持其他路由事件功能,例如类处理、System.Windows.EventTrigger 或 System.Windows.EventSetter。
        //    Direct = 2,
        //}
        #endregion
      
        /// <summary>
        /// 用静态的构造函数 注册路由事件
        /// </summary>
        static RoutedEventEx()
        {
            RoutedEventEx.ClickEvent = EventManager.RegisterRoutedEvent("ClickEx", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(RoutedEventEx));
        }
        /// <summary>
        /// 封装路由事件 从而使所有.NET语言都能访问
        /// </summary>
        public event RoutedEventHandler ClickEx
        {
            add
            {
                AddHandler(RoutedEventEx.ClickEvent, value);
            }
            remove
            {
                RemoveHandler(RoutedEventEx.ClickEvent, value);
            }
        }
        //AddHandler   RemoveHandler 这两个方法是FrameworkElement 基类中定义
 
 
 

       //共享路由事件
      //   UIElement.MouseUpEvent = Mouse.MouseUpEvent.AddWwner(typeof(UIElement));
        //引发路由事件
        private void RaiseEventEx()
        {
            RoutedEventArgs e = new RoutedEventArgs(RoutedEventEx.ClickEvent, this);
            base.RaiseEvent(e);
        }
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值