/// <inheritdoc /> protected override void OnTemplateApplied(TemplateAppliedEventArgs e) { if (TextBox != null) { TextBox.PointerPressed -= TextBoxOnPointerPressed; _textBoxTextChangedSubscription?.Dispose(); } TextBox = e.NameScope.Find <TextBox>("PART_TextBox"); if (TextBox != null) { TextBox.Text = Text; TextBox.PointerPressed += TextBoxOnPointerPressed; _textBoxTextChangedSubscription = TextBox.GetObservable(TextBox.TextProperty).Subscribe(txt => TextBoxOnTextChanged()); } if (Spinner != null) { Spinner.Spin -= OnSpinnerSpin; } Spinner = e.NameScope.Find <Spinner>("PART_Spinner"); if (Spinner != null) { Spinner.Spin += OnSpinnerSpin; } SetValidSpinDirection(); }
protected override void OnTemplateApplied(TemplateAppliedEventArgs e) { if (_calendar != null) { _calendar.DayButtonMouseUp -= Calendar_DayButtonMouseUp; _calendar.DisplayDateChanged -= Calendar_DisplayDateChanged; _calendar.SelectedDatesChanged -= Calendar_SelectedDatesChanged; _calendar.PointerPressed -= Calendar_PointerPressed; _calendar.KeyDown -= Calendar_KeyDown; } _calendar = e.NameScope.Find <Calendar>(ElementCalendar); if (_calendar != null) { _calendar.SelectionMode = CalendarSelectionMode.SingleDate; _calendar.SelectedDate = SelectedDate; SetCalendarDisplayDate(DisplayDate); SetCalendarDisplayDateStart(DisplayDateStart); SetCalendarDisplayDateEnd(DisplayDateEnd); _calendar.DayButtonMouseUp += Calendar_DayButtonMouseUp; _calendar.DisplayDateChanged += Calendar_DisplayDateChanged; _calendar.SelectedDatesChanged += Calendar_SelectedDatesChanged; _calendar.PointerPressed += Calendar_PointerPressed; _calendar.KeyDown += Calendar_KeyDown; //_calendar.SizeChanged += new SizeChangedEventHandler(Calendar_SizeChanged); //_calendar.IsTabStop = true; var currentBlackoutDays = BlackoutDates; BlackoutDates = _calendar.BlackoutDates; if (currentBlackoutDays != null) { foreach (var range in currentBlackoutDays) { BlackoutDates.Add(range); } } } if (_popUp != null) { _popUp.Child = null; _popUp.Closed -= PopUp_Closed; } _popUp = e.NameScope.Find <Popup>(ElementPopup); if (_popUp != null) { _popUp.Closed += PopUp_Closed; if (IsDropDownOpen) { OpenDropDown(); } } if (_dropDownButton != null) { _dropDownButton.Click -= DropDownButton_Click; _buttonPointerPressedSubscription?.Dispose(); } _dropDownButton = e.NameScope.Find <Button>(ElementButton); if (_dropDownButton != null) { _dropDownButton.Click += DropDownButton_Click; _buttonPointerPressedSubscription = _dropDownButton.AddHandler(PointerPressedEvent, DropDownButton_PointerPressed, handledEventsToo: true); } if (_textBox != null) { _textBox.KeyDown -= TextBox_KeyDown; _textBox.GotFocus -= TextBox_GotFocus; _textBoxTextChangedSubscription?.Dispose(); } _textBox = e.NameScope.Find <TextBox>(ElementTextBox); if (!SelectedDate.HasValue) { SetWaterMarkText(); } if (_textBox != null) { _textBox.KeyDown += TextBox_KeyDown; _textBox.GotFocus += TextBox_GotFocus; _textBoxTextChangedSubscription = _textBox.GetObservable(TextBox.TextProperty).Subscribe(txt => TextBox_TextChanged()); if (SelectedDate.HasValue) { _textBox.Text = DateTimeToString(SelectedDate.Value); } else if (!String.IsNullOrEmpty(_defaultText)) { _textBox.Text = _defaultText; SetSelectedDate(); } } base.OnTemplateApplied(e); }