心澄欲遣

不践迹,亦不入于室

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

简单的定义下面的路由事件类,死东西,敲熟练

  public class MyRoutedEvents : UIElement
    {
        public static readonly RoutedEvent ButtonClickEvent = EventManager.RegisterRoutedEvent("ButtonClick", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(MyRoutedEvents));

        public event RoutedEventHandler ButtonClick
        {
            add { AddHandler(ButtonClickEvent, value); }
            remove { RemoveHandler(ButtonClickEvent, value); }
        }

        public void SendEvent(RoutedEvent evt, RoutedEventArgs e)
        {
            e.RoutedEvent = evt;
            RaiseEvent(e);
        }

        public virtual void OnButtonClick()
        {
            SendEvent(ButtonClickEvent, new RoutedEventArgs());
        }
    }
View Code

前台需要一个控件的事件来激活

 private void img__MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            MyRoutedEvents routed = new MyRoutedEvents();
            routed.ButtonClick += new RoutedEventHandler((object sender2, RoutedEventArgs evte) => {
                MessageBox.Show("Clicked me.");
            });
            routed.OnButtonClick();
        }
View Code

ok了。

posted on 2013-06-24 10:09  心澄欲遣  阅读(245)  评论(0编辑  收藏  举报
欢迎第myspace graphics个访客