public delegate void MenuButtonClickEventHandler(object sender, EventArgs e);
public event MenuButtonClickEventHandler MenuButtonClick
{
add
{
this.AddHandler(MenuButtonClickEvent, value);
}
remove
{
this.RemoveHandler(MenuButtonClickEvent, value);
}
}
public static readonly RoutedEvent MenuButtonClickEvent = EventManager.RegisterRoutedEvent("MenuButtonClick", RoutingStrategy.Bubble, typeof(MenuButtonClickEventHandler), typeof(MultiDimensionsAnalysis));
private void Button_Click(object sender, RoutedEventArgs e)
{
this.RaiseEvent(new RoutedEventArgs(MenuButtonClickEvent, sender));//sender就是参数button,把这个button传给外部
}
xaml用户控件声明事件********MenuButtonClick="MenuButtonClick"
cs代码 private void MenuButtonClick(object sender, EventArgs e)//sender接受到的参数button
{
var obj = (e as RoutedEventArgs).OriginalSource as Button;
Button_Click(obj, null);
}