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


C# ButtonBase.SetBinding方法代码示例

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


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

示例1: 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


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