public override void OnApplyTemplate() { if (pickerBase != null) { pickerBase.DropDownClosed -= new RoutedEventHandler(pickerBase_DropDownClosed); pickerBase.DropDownOpened -= new RoutedEventHandler(pickerBase_DropDownOpened); } textBox = (TextBox)GetTemplateChild("PART_EditableTextBox"); colorSelector = (ColorSelector)GetTemplateChild("PART_ColorSelector"); pickerBase = (PickerBase)GetTemplateChild("PART_PickerBase"); if (pickerBase != null) { pickerBase.DropDownClosed += new RoutedEventHandler(pickerBase_DropDownClosed); pickerBase.DropDownOpened += new RoutedEventHandler(pickerBase_DropDownOpened); } UpdateVisibility(); }
public override void OnApplyTemplate() { if (textBox != null) BindingOperations.ClearBinding(textBox, TextBox.TextProperty); textBox = (TextBox)GetTemplateChild("PART_EditableTextBox"); if (textBox != null) BindingOperations.SetBinding(textBox, TextBox.TextProperty, new Binding { Source = this, Path = new PropertyPath(SelectedDateProperty), Converter = DateTimeConverter, Mode = BindingMode.TwoWay, ValidatesOnDataErrors = true, ValidatesOnExceptions = true, NotifyOnValidationError = true, UpdateSourceTrigger = UpdateSourceTrigger.LostFocus, }.Do(b => b.ValidationRules.Add(DateTimeConverter))); if (pickerBase != null) pickerBase.DropDownOpened -= pickerBase_DropDownOpened; pickerBase = (PickerBase)GetTemplateChild("PART_PickerBase"); if (pickerBase != null) pickerBase.DropDownOpened += pickerBase_DropDownOpened; if (monthCalendar != null) { monthCalendar.SelectedDatesChanged -= monthCalendar_SelectedDatesChanged; BindingOperations.ClearBinding(monthCalendar, System.Windows.Controls.Calendar.SelectedDateProperty); } monthCalendar = (System.Windows.Controls.Calendar)GetTemplateChild("PART_DatePickerCalendar"); if (monthCalendar != null) { monthCalendar.SelectedDatesChanged += monthCalendar_SelectedDatesChanged; BindingOperations.SetBinding(monthCalendar, System.Windows.Controls.Calendar.SelectedDateProperty, new Binding { Source = this, Path = new PropertyPath(SelectedDateProperty), Mode = BindingMode.TwoWay, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged }); } UpdateVisibility(); }
public override void OnApplyTemplate() { if (textBox != null) { BindingOperations.ClearBinding(textBox, TextBox.TextProperty); } textBox = (TextBox)GetTemplateChild("PART_EditableTextBox"); if (textBox != null) { BindingOperations.SetBinding(textBox, TextBox.TextProperty, new Binding { Source = this, Path = new PropertyPath(SelectedDateProperty), Converter = DateTimeConverter, Mode = BindingMode.TwoWay, ValidatesOnDataErrors = true, ValidatesOnExceptions = true, NotifyOnValidationError = true, UpdateSourceTrigger = UpdateSourceTrigger.LostFocus, }.Do(b => b.ValidationRules.Add(DateTimeConverter))); } if (pickerBase != null) { pickerBase.DropDownOpened -= pickerBase_DropDownOpened; } pickerBase = (PickerBase)GetTemplateChild("PART_PickerBase"); if (pickerBase != null) { pickerBase.DropDownOpened += pickerBase_DropDownOpened; } if (monthCalendar != null) { monthCalendar.SelectedDatesChanged -= monthCalendar_SelectedDatesChanged; BindingOperations.ClearBinding(monthCalendar, System.Windows.Controls.Calendar.SelectedDateProperty); } monthCalendar = (System.Windows.Controls.Calendar)GetTemplateChild("PART_DatePickerCalendar"); if (monthCalendar != null) { monthCalendar.SelectedDatesChanged += monthCalendar_SelectedDatesChanged; BindingOperations.SetBinding(monthCalendar, System.Windows.Controls.Calendar.SelectedDateProperty, new Binding { Source = this, Path = new PropertyPath(SelectedDateProperty), Mode = BindingMode.TwoWay, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged }); } UpdateVisibility(); }