如何在WPF中声明var的类型委托RoutedPropertyChangedEventHandler?

时间:2011-01-23 18:30:39

标签: wpf wpf-controls

我找不到为我的用户控件类型委托RoutedPropertyChangedEventHandler声明属性的语法(如滑块ValueChange处理程序)

http://msdn.microsoft.com/en-us/library/ms589771.aspx

1 个答案:

答案 0 :(得分:1)

您正在尝试创建活动:

public event RoutedPropertyChangedEventHandler MyEvent;

但是,为了使其正常工作,您需要创建routed event

public static readonly RoutedEvent TapEvent = EventManager.RegisterRoutedEvent(
    "Tap", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(MyButtonSimple));

// Provide CLR accessors for the event
public event RoutedEventHandler Tap
{
        add { AddHandler(TapEvent, value); } 
        remove { RemoveHandler(TapEvent, value); }
}