wpf 用戶自定義事件傳參2

        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);
        }
相關文章
相關標籤/搜索