当前位置: 首页>>代码示例>>C#>>正文


C# ButtonBase.AddHandler方法代码示例

本文整理汇总了C#中System.Windows.Controls.Primitives.ButtonBase.AddHandler方法的典型用法代码示例。如果您正苦于以下问题:C# ButtonBase.AddHandler方法的具体用法?C# ButtonBase.AddHandler怎么用?C# ButtonBase.AddHandler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Controls.Primitives.ButtonBase的用法示例。


在下文中一共展示了ButtonBase.AddHandler方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnApplyTemplate

        /// <summary>
        /// Builds the visual tree for the DatePicker control when a new template is applied.
        /// </summary>
        public override void OnApplyTemplate()
        {
            if (_popUp != null)
            {
                _popUp.RemoveHandler(PreviewMouseLeftButtonDownEvent, new MouseButtonEventHandler(PopUp_PreviewMouseLeftButtonDown));
                _popUp.Opened -= PopUp_Opened;
                _popUp.Closed -= PopUp_Closed;
                _popUp.Child = null;
            }

            if (_dropDownButton != null)
            {
                _dropDownButton.Click -= DropDownButton_Click;
                _dropDownButton.RemoveHandler(MouseLeaveEvent, new MouseEventHandler(DropDownButton_MouseLeave));
            }

            if (_textBox != null)
            {
                _textBox.RemoveHandler(TextBox.KeyDownEvent, new KeyEventHandler(TextBox_KeyDown));
                _textBox.RemoveHandler(TextBox.TextChangedEvent, new TextChangedEventHandler(TextBox_TextChanged));
                _textBox.RemoveHandler(TextBox.LostFocusEvent, new RoutedEventHandler(TextBox_LostFocus));
            }

            base.OnApplyTemplate();

            _popUp = GetTemplateChild(ElementPopup) as Popup;

            if (_popUp != null)
            {
                _popUp.AddHandler(PreviewMouseLeftButtonDownEvent, new MouseButtonEventHandler(PopUp_PreviewMouseLeftButtonDown));
                _popUp.Opened += PopUp_Opened;
                _popUp.Closed += PopUp_Closed;
                _popUp.Child = this._calendar;

                if (this.IsDropDownOpen)
                {
                    this._popUp.IsOpen = true;
                }
            }

            _dropDownButton = GetTemplateChild(ElementButton) as Button;
            if (_dropDownButton != null)
            {
                _dropDownButton.Click += DropDownButton_Click;
                _dropDownButton.AddHandler(MouseLeaveEvent, new MouseEventHandler(DropDownButton_MouseLeave), true);

                // If the user does not provide a Content value in template, we provide a helper text that can be used in Accessibility
                // this text is not shown on the UI, just used for Accessibility purposes
                if (_dropDownButton.Content == null)
                {
                    _dropDownButton.Content = SR.Get(SRID.DatePicker_DropDownButtonName);
                }
            }

            _textBox = GetTemplateChild(ElementTextBox) as DatePickerTextBox;

            if (this.SelectedDate == null)
            {
                SetWaterMarkText();
            }

            if (_textBox != null)
            {
                _textBox.AddHandler(TextBox.KeyDownEvent, new KeyEventHandler(TextBox_KeyDown), true);
                _textBox.AddHandler(TextBox.TextChangedEvent, new TextChangedEventHandler(TextBox_TextChanged), true);
                _textBox.AddHandler(TextBox.LostFocusEvent, new RoutedEventHandler(TextBox_LostFocus), true);

                if (this.SelectedDate == null)
                {
                    if (!string.IsNullOrEmpty(this._defaultText))
                    {
                        _textBox.Text = this._defaultText;
                        SetSelectedDate();
                    }
                }
                else
                {
                    _textBox.Text = this.DateTimeToString((DateTime)this.SelectedDate);
                }
            }
        }
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:84,代码来源:DatePicker.cs

示例2: OnApplyTemplate

        /// <summary>
        /// Builds the visual tree for the DatePicker control when a new template is applied. 
        /// </summary>
        public override void OnApplyTemplate() {
            ReleaseCalendar();
            if (_popUp != null) {
                _popUp.RemoveHandler(PreviewMouseLeftButtonDownEvent, new MouseButtonEventHandler(PopUp_PreviewMouseLeftButtonDown));
                _popUp.Opened -= PopUp_Opened;
                _popUp.Closed -= PopUp_Closed;
                _popUp.Child = null;
            }

            if (_dropDownButton != null) {
                _dropDownButton.Click -= DropDownButton_Click;
                _dropDownButton.RemoveHandler(MouseLeaveEvent, new MouseEventHandler(DropDownButton_MouseLeave));
            }

            if (_todayButton != null) {
                _todayButton.Click -= TodayButton_Click;
                BindingOperations.ClearAllBindings(_todayButton);
            }

            if (_clearButton != null) {
                _clearButton.Click -= ClearButton_Click;
                BindingOperations.ClearAllBindings(_clearButton);
            }

            if (_textBox != null) {
                FocusManager.SetIsFocusScope(_textBox, false);
                _textBox.Focusable = true;
                _textBox.RemoveHandler(KeyDownEvent, new KeyEventHandler(TextBox_KeyDown));
                _textBox.RemoveHandler(TextBoxBase.TextChangedEvent, new TextChangedEventHandler(TextBox_TextChanged));
                _textBox.RemoveHandler(LostFocusEvent, new RoutedEventHandler(TextBox_LostFocus));
            }

            base.OnApplyTemplate();

            _calendar = GetTemplateChild(PartCalendarName) as Calendar;
            InitializeCalendar();

            _popUp = GetTemplateChild(PartPopupName) as Popup;

            if (_popUp != null) {
                _popUp.AddHandler(PreviewMouseLeftButtonDownEvent, new MouseButtonEventHandler(PopUp_PreviewMouseLeftButtonDown));
                _popUp.Opened += PopUp_Opened;
                _popUp.Closed += PopUp_Closed;
                // While we have a calendar part in control's template ,this line is no longer necessary
                // _popUp.Child = _calendar;
                if (IsDropDownOpen)
                    _popUp.IsOpen = true;
            }

            _dropDownButton = GetTemplateChild(PartDropDownButtonName) as Button;
            if (_dropDownButton != null) {
                _dropDownButton.Click += DropDownButton_Click;
                _dropDownButton.AddHandler(MouseLeaveEvent, new MouseEventHandler(DropDownButton_MouseLeave), true);
                // If the user does not provide a Content value in template, we 
                // provide a helper text that can be used in Accessibility. This
                // text is not shown on the UI, just used for Accessibility purposes
                if (_dropDownButton.Content == null)
                    _dropDownButton.Content = "Select";
            }

            _todayButton = GetTemplateChild(PartTodayButtonName) as ButtonBase;
            if (_todayButton != null) {
                _todayButton.Click += TodayButton_Click;
                _todayButton.SetBinding(StyleProperty, GetSelfBinding(TodayButtonStyleProperty));
                SetTodayButtonContent();
            }

            _clearButton = GetTemplateChild(PartClearButtonName) as ButtonBase;
            if (_clearButton != null) {
                _clearButton.Click += ClearButton_Click;
                _clearButton.SetBinding(StyleProperty, GetSelfBinding(ClearButtonStyleProperty));
                _clearButton.SetBinding(ContentControl.ContentProperty, GetSelfBinding(ClearButtonContentProperty));
            }

            _textBox = GetTemplateChild(PartTextBoxName) as DatePickerTextBox;

            if (SelectedDate == null) {
                SetWaterMarkText();
            }

            if (_textBox != null) {
                _textBox.AddHandler(KeyDownEvent, new KeyEventHandler(TextBox_KeyDown), true);
                _textBox.AddHandler(TextBoxBase.TextChangedEvent, new TextChangedEventHandler(TextBox_TextChanged), true);
                _textBox.AddHandler(LostFocusEvent, new RoutedEventHandler(TextBox_LostFocus), true);

                if (SelectedDate == null) {
                    if (!string.IsNullOrEmpty(_defaultText)) {
                        _textBox.Text = _defaultText;
                        SetSelectedDate();
                    }
                } else
                    _textBox.Text = DateTimeToString((DateTime)SelectedDate);
            }
            UpdateVisualState(true);
        }
开发者ID:kavand,项目名称:Kavand.Windows.Controls,代码行数:98,代码来源:DatePicker.cs

示例3: OnApplyTemplate

        /// <summary>
        /// Builds the visual tree for the DatePicker control when a new template is applied.
        /// </summary>
        public override void OnApplyTemplate()
        {
            if (_popUp != null)
            {
                _popUp.RemoveHandler(PreviewMouseLeftButtonDownEvent, new MouseButtonEventHandler(PopUp_PreviewMouseLeftButtonDown));
                _popUp.Opened -= PopUp_Opened;
                _popUp.Closed -= PopUp_Closed;
                _popUp.Child = null;
            }

            if (_dropDownButton != null)
            {
                _dropDownButton.Click -= DropDownButton_Click;
                _dropDownButton.RemoveHandler(MouseLeaveEvent, new MouseEventHandler(DropDownButton_MouseLeave));
            }

            if (_textBox != null)
            {
                _textBox.RemoveHandler(TextBox.KeyDownEvent, new KeyEventHandler(TextBox_KeyDown));
                _textBox.RemoveHandler(TextBox.TextChangedEvent, new TextChangedEventHandler(TextBox_TextChanged));
                _textBox.RemoveHandler(TextBox.LostFocusEvent, new RoutedEventHandler(TextBox_LostFocus));
            }

            base.OnApplyTemplate();

            _popUp = GetTemplateChild(ElementPopup) as Popup;

            if (_popUp != null)
            {
                _popUp.AddHandler(PreviewMouseLeftButtonDownEvent, new MouseButtonEventHandler(PopUp_PreviewMouseLeftButtonDown));
                _popUp.Opened += PopUp_Opened;
                _popUp.Closed += PopUp_Closed;
                _popUp.Child = this._calendar;

                if (this.IsDropDownOpen)
                {
                    this._popUp.IsOpen = true;
                }
            }

            _dropDownButton = GetTemplateChild(ElementButton) as Button;
            if (_dropDownButton != null)
            {
                _dropDownButton.Click += DropDownButton_Click;
                _dropDownButton.AddHandler(MouseLeaveEvent, new MouseEventHandler(DropDownButton_MouseLeave), true);

                // If the user does not provide a Content value in template, we provide a helper text that can be used in Accessibility
                // this text is not shown on the UI, just used for Accessibility purposes
                if (_dropDownButton.Content == null)
                {
                    _dropDownButton.Content = SR.Get(SRID.DatePicker_DropDownButtonName);
                }
            }

            _textBox = GetTemplateChild(ElementTextBox) as DatePickerTextBox;

            UpdateDisabledVisual();
            if (this.SelectedDate == null)
            {
                SetWaterMarkText();
            }

            if (_textBox != null)
            {
                _textBox.AddHandler(TextBox.KeyDownEvent, new KeyEventHandler(TextBox_KeyDown), true);
                _textBox.AddHandler(TextBox.TextChangedEvent, new TextChangedEventHandler(TextBox_TextChanged), true);
                _textBox.AddHandler(TextBox.LostFocusEvent, new RoutedEventHandler(TextBox_LostFocus), true);

                if (this.SelectedDate == null)
                {
                    if (!string.IsNullOrEmpty(this._defaultText))
                    {
                        _textBox.Text = this._defaultText;
                        SetSelectedDate();
                    }
                }
                else
                {
                    _textBox.Text = this.DateTimeToString((DateTime)this.SelectedDate);
                }
            }

            if (IsButtonDynamicShow)
            {
                _dropDownButton.Visibility = System.Windows.Visibility.Collapsed;
                Grid oGrid = GetTemplateChild("PART_Root") as Grid;
                oGrid.MouseEnter += new MouseEventHandler(_popUp_MouseEnter);
                oGrid.MouseLeave += new MouseEventHandler(_popUp_MouseLeave);
            }
            if (HideTextBoxBackground)
            {
                _textBox.Watermark = string.Empty;
                _textBox.BorderBrush = null;
                _textBox.BorderThickness = new Thickness(0);
                _textBox.Background = null;
                this.BorderThickness = new Thickness(0);
            }
//.........这里部分代码省略.........
开发者ID:merlin2504,项目名称:RD12,代码行数:101,代码来源:DatePicker.cs


注:本文中的System.Windows.Controls.Primitives.ButtonBase.AddHandler方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。