/// <inheritdoc/> protected override void OnApplyTemplate(TemplateAppliedEventArgs e) { base.OnApplyTemplate(e); _decreaseButtonPressDispose?.Dispose(); _decreaseButtonReleaseDispose?.Dispose(); _increaseButtonSubscription?.Dispose(); _increaseButtonReleaseDispose?.Dispose(); _pointerMovedDispose?.Dispose(); _decreaseButton = e.NameScope.Find <Button>("PART_DecreaseButton"); _track = e.NameScope.Find <Track>("PART_Track"); _increaseButton = e.NameScope.Find <Button>("PART_IncreaseButton"); if (_track != null) { _track.IsThumbDragHandled = true; } if (_decreaseButton != null) { _decreaseButtonPressDispose = _decreaseButton.AddDisposableHandler(PointerPressedEvent, TrackPressed, RoutingStrategies.Tunnel); _decreaseButtonReleaseDispose = _decreaseButton.AddDisposableHandler(PointerReleasedEvent, TrackReleased, RoutingStrategies.Tunnel); } if (_increaseButton != null) { _increaseButtonSubscription = _increaseButton.AddDisposableHandler(PointerPressedEvent, TrackPressed, RoutingStrategies.Tunnel); _increaseButtonReleaseDispose = _increaseButton.AddDisposableHandler(PointerReleasedEvent, TrackReleased, RoutingStrategies.Tunnel); } _pointerMovedDispose = this.AddDisposableHandler(PointerMovedEvent, TrackMoved, RoutingStrategies.Tunnel); }
protected override void OnApplyTemplate(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.AddDisposableHandler(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(); } } }