zoukankan      html  css  js  c++  java
  • 简单的应用路由事件

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

      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了。

  • 相关阅读:
    桥接模式
    单例模式
    迭代器模式
    组合模式
    备忘录模式
    适配器模式
    状态模式
    观察者模式
    golang 字符串统计
    go bytes缓冲区使用介绍 -转自https://www.cnblogs.com/--xiaoyao--/p/5122138.html
  • 原文地址:https://www.cnblogs.com/smartsensor/p/3151974.html
Copyright © 2011-2022 走看看