zoukankan      html  css  js  c++  java
  • wpf 用户自定义事件传参

    //自定义传参 ,对外联系的参数
    public class ImageZoomChangedEventArgs : RoutedEventArgs
        {
            /// <summary>
            /// 放大倍数,1:原始尺寸
            /// </summary>
            public int Zoom { get; set; }
            public ImageZoomChangedEventArgs(RoutedEvent routedEvent, int value) : base(routedEvent)
            {
                this.Zoom = value;
            }
        }
    
    
    
    //用户自定义事件
            public delegate void ZoomChangedEventHandler(object sender, EventArgs e);
            public event ZoomChangedEventHandler ZoomChanged
            {
                add
                {
                    this.AddHandler(ZoomChangedEvent, value);
                }
    
                remove
                {
                    this.RemoveHandler(ZoomChangedEvent, value);
                }
            }
            public static readonly RoutedEvent ZoomChangedEvent = EventManager.RegisterRoutedEvent("ZoomChanged", RoutingStrategy.Bubble, typeof(ZoomChangedEventHandler), typeof(HZImageViewerEx));
    
    
        //触发自定义事件
         void OnPreviewMouseWheel(object sender, MouseWheelEventArgs e)
            {
            this.RaiseEvent(new ImageZoomChangedEventArgs(ZoomChangedEvent, (int)slider.Value));
           }
    
    //外部接收的事件处理方法 
    private void img_ZoomChanged(object sender, EventArgs e) 
    {
        var args = (ImageZoomChangedEventArgs)e;     
             if(args.Zoom!=1) 
             {
                   .... 
              }
     }    
  • 相关阅读:
    Investment
    The Fewest Coins
    Bone Collector II
    Cow Exhibition
    饭卡
    A + B Problem II
    F
    敌兵布阵
    单例模式
    面向对象
  • 原文地址:https://www.cnblogs.com/zsx-blog/p/8193618.html
Copyright © 2011-2022 走看看