本文整理汇总了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);
}