public override void OnApplyTemplate() { base.OnApplyTemplate(); var spinDownName = Strings.NumberBoxDownSpinButtonName; var spinUpName = Strings.NumberBoxUpSpinButtonName; if (GetTemplateChild(c_numberBoxDownButtonName) is RepeatButton spinDown) { spinDown.Click += OnSpinDownClick; // Do localization for the down button if (string.IsNullOrEmpty(AutomationProperties.GetName(spinDown))) { AutomationProperties.SetName(spinDown, spinDownName); } } if (GetTemplateChild(c_numberBoxUpButtonName) is RepeatButton spinUp) { spinUp.Click += OnSpinUpClick; // Do localization for the up button if (string.IsNullOrEmpty(AutomationProperties.GetName(spinUp))) { AutomationProperties.SetName(spinUp, spinUpName); } } UpdateHeaderPresenterState(); m_textBox = GetTextBox(); TextBox GetTextBox() { var textBox = GetTemplateChild(c_numberBoxTextBoxName) as TextBox; if (textBox != null) { if (SharedHelpers.IsRS3OrHigher()) { // Listen to PreviewKeyDown because textbox eats the down arrow key in some circumstances. textBox.PreviewKeyDown += OnNumberBoxKeyDown; } else { // This is better than nothing. textBox.KeyDown += OnNumberBoxKeyDown; } textBox.KeyUp += OnNumberBoxKeyUp; // Listen to NumberBox::CornerRadius changes so that we can enfore the T-rule for the textbox in SpinButtonPlacementMode::Inline. // We need to explicitly go to the corresponding visual state each time the NumberBox' CornerRadius is changed in order for the new // corner radius values to be filtered correctly. // If we only go to the SpinButtonsVisible visual state whenever the SpinButtonPlacementMode is changed to Inline, all subsequent // corner radius changes would apply to all four textbox corners (this can be easily seen in the CornerRadius test page of the MUXControlsTestApp). // This will break the T-rule in the Inline SpinButtonPlacementMode. // Not needed for WPF. /* * if (SharedHelpers.IsControlCornerRadiusAvailable()) * { * RegisterPropertyChanged(Control.CornerRadiusProperty, OnCornerRadiusPropertyChanged); * } */ } return(textBox); } m_popup = GetTemplateChild(c_numberBoxPopupName) as Popup; if (m_popup != null) { if (m_popup.HasDefaultValue(Popup.PlacementTargetProperty)) { m_popup.PlacementTarget = m_textBox; } m_popupRepositionHelper = new PopupRepositionHelper(m_popup, this); } if (GetTemplateChild(c_numberBoxPopupDownButtonName) is RepeatButton popupSpinDown) { popupSpinDown.Click += OnSpinDownClick; } if (GetTemplateChild(c_numberBoxPopupUpButtonName) is RepeatButton popupSpinUp) { popupSpinUp.Click += OnSpinUpClick; } IsEnabledChanged += OnIsEnabledChanged; // .NET rounds to 12 significant digits when displaying doubles, so we will do the same. //m_displayRounder.SignificantDigits(12); UpdateSpinButtonPlacement(); UpdateSpinButtonEnabled(); UpdateVisualStateForIsEnabledChange(); if (ReadLocalValue(ValueProperty) == DependencyProperty.UnsetValue && ReadLocalValue(TextProperty) != DependencyProperty.UnsetValue) { // If Text has been set, but Value hasn't, update Value based on Text. UpdateValueToText(); } else { UpdateTextToValue(); } }
public override void OnApplyTemplate() { if (m_textBox != null) { m_textBox.TextChanged -= OnTextBoxTextChanged; m_textBox.PreviewKeyDown -= OnTextBoxPreviewKeyDown; } if (m_queryButton != null) { m_queryButton.Click -= OnQueryButtonClick; m_queryButton.ClearValue(ContentControl.ContentProperty); m_queryButton = null; } if (m_suggestionsPopup != null) { m_suggestionsPopup.Opened -= OnSuggestionsPopupOpened; m_suggestionsPopup.Closed -= OnSuggestionsPopupClosed; m_suggestionsPopup.ClearValue(Popup.PlacementTargetProperty); } if (m_popupRepositionHelper != null) { m_popupRepositionHelper.Dispose(); m_popupRepositionHelper = null; } if (m_suggestionsList != null) { m_suggestionsList.Loaded -= OnSuggestionsListLoaded; m_suggestionsList.SelectionChanged -= OnSuggestionsListSelectionChanged; m_suggestionsList.ItemClick -= OnSuggestionsListItemClick; } base.OnApplyTemplate(); m_textBox = GetTemplateChild(c_textBoxName) as TextBox; m_suggestionsPopup = GetTemplateChild(c_popupName) as Popup; m_suggestionsList = GetTemplateChild("SuggestionsList") as AutoSuggestBoxListView; if (m_textBox != null) { m_textBox.ApplyTemplate(); m_queryButton = m_textBox.GetTemplateChild <Button>("QueryButton"); m_textBox.TextChanged += OnTextBoxTextChanged; m_textBox.PreviewKeyDown += OnTextBoxPreviewKeyDown; UpdateTextBox(); } if (m_queryButton != null) { m_queryButton.Click += OnQueryButtonClick; OnQueryIconChanged(null, QueryIcon); } if (m_suggestionsPopup != null) { m_suggestionsPopup.Opened += OnSuggestionsPopupOpened; m_suggestionsPopup.Closed += OnSuggestionsPopupClosed; m_popupRepositionHelper = new PopupRepositionHelper(m_suggestionsPopup, this); if (m_textBox != null) { var textBoxBorder = m_textBox.GetTemplateChild <FrameworkElement>(c_textBoxBorderName); if (textBoxBorder != null) { m_suggestionsPopup.PlacementTarget = textBoxBorder; } } } if (m_suggestionsList != null) { m_suggestionsList.Loaded += OnSuggestionsListLoaded; m_suggestionsList.SelectionChanged += OnSuggestionsListSelectionChanged; m_suggestionsList.ItemClick += OnSuggestionsListItemClick; } }
public override void OnApplyTemplate() { base.OnApplyTemplate(); var spinDownName = Strings.NumberBoxDownSpinButtonName; var spinUpName = Strings.NumberBoxUpSpinButtonName; if (GetTemplateChild(c_numberBoxDownButtonName) is RepeatButton spinDown) { spinDown.Click += OnSpinDownClick; // Do localization for the down button if (string.IsNullOrEmpty(AutomationProperties.GetName(spinDown))) { AutomationProperties.SetName(spinDown, spinDownName); } } if (GetTemplateChild(c_numberBoxUpButtonName) is RepeatButton spinUp) { spinUp.Click += OnSpinUpClick; // Do localization for the up button if (string.IsNullOrEmpty(AutomationProperties.GetName(spinUp))) { AutomationProperties.SetName(spinUp, spinUpName); } } if (GetTemplateChild(c_numberBoxTextBoxName) is TextBox textBox) { textBox.PreviewKeyDown += OnNumberBoxKeyDown; textBox.KeyUp += OnNumberBoxKeyUp; m_textBox = textBox; } m_popup = GetTemplateChild(c_numberBoxPopupName) as Popup; if (m_popup != null) { if (m_popup.HasDefaultValue(Popup.PlacementTargetProperty)) { m_popup.PlacementTarget = m_textBox; } m_popupRepositionHelper = new PopupRepositionHelper(m_popup, this); } if (GetTemplateChild(c_numberBoxPopupDownButtonName) is RepeatButton popupSpinDown) { popupSpinDown.Click += OnSpinDownClick; } if (GetTemplateChild(c_numberBoxPopupUpButtonName) is RepeatButton popupSpinUp) { popupSpinUp.Click += OnSpinUpClick; } // .NET rounds to 12 significant digits when displaying doubles, so we will do the same. //m_displayRounder.SignificantDigits(12); UpdateSpinButtonPlacement(); UpdateSpinButtonEnabled(); if (ReadLocalValue(ValueProperty) == DependencyProperty.UnsetValue && ReadLocalValue(TextProperty) != DependencyProperty.UnsetValue) { // If Text has been set, but Value hasn't, update Value based on Text. UpdateValueToText(); } else { UpdateTextToValue(); } }