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) { .... } }
posted on 2018-01-04 15:28 Shine-Zhong 阅读(627) 评论(0) 编辑 收藏 举报