Primitive control - TextBox with UpPressed and DownPressed events for use in a NumericUpDown to make up and down keys work to increment and decrement the values.
Inheritance: Windows.UI.Xaml.Controls.TextBox
 /// <summary>
 /// Invoked whenever application code or internal processes (such as a rebuilding layout pass) call ApplyTemplate. In simplest terms, this means the method is called just before a UI element displays in your app. Override this method to influence the default post-template logic of a class.
 /// </summary>
 protected override void OnApplyTemplate()
 {
     this.UnsubscribeEvents();
     this.textBox = this.GetTemplateChild(TextBoxPropertyName) as UpDownTextBox;
     this.autoCompletePresenter            = this.GetTemplateChild(AutoCompletePresenterPropertyName) as Popup;
     this.autoCompletePresenter.Width      = this.ActualWidth;
     this.autocompleteItemsContainer       = this.GetTemplateChild(AutocompleteItemsContainerPropertyName) as SimpleThemingListBox;
     this.autocompleteItemsContainer.Width = this.ActualWidth;
     this.SetBorderThickness();
     base.OnApplyTemplate();
     this.SubscribeEvents();
 }
Exemplo n.º 2
0
        /// <summary>
        /// Invoked whenever application code or internal processes (such as a rebuilding layout pass) call ApplyTemplate. In simplest terms, this means the method is called just before a UI element displays in your app. Override this method to influence the default post-template logic of a class.
        /// </summary>
        protected override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            if (DesignMode.DesignModeEnabled)
            {
                return;
            }

            this.GotFocus += this.OnGotFocus;
            this.LostFocus += this.OnLostFocus;
            this.PointerWheelChanged += this.OnPointerWheelChanged;
            _valueTextBox = this.GetTemplateChild(ValueTextBoxName) as UpDownTextBox;
            _dragOverlay = this.GetTemplateChild(DragOverlayName) as UIElement;
            _decrementButton = this.GetTemplateChild(DecrementButtonName) as RepeatButton;
            _incrementButton = this.GetTemplateChild(IncrementButtonName) as RepeatButton;
            _valueBar = this.GetTemplateChild(ValueBarName) as FrameworkElement;
            
            if (_valueTextBox != null)
            {
                _valueTextBox.LostFocus += this.OnValueTextBoxLostFocus;
                _valueTextBox.GotFocus += this.OnValueTextBoxGotFocus;
                _valueTextBox.Text = this.Value.ToString(CultureInfo.CurrentCulture);
                _valueTextBox.TextChanged += this.OnValueTextBoxTextChanged;
                _valueTextBox.KeyDown += this.OnValueTextBoxKeyDown;
                _valueTextBox.UpPressed += (s, e) => this.Increment();
                _valueTextBox.DownPressed += (s, e) => this.Decrement();
                _valueTextBox.PointerExited += this.OnValueTextBoxPointerExited;
            }

            if (_dragOverlay != null)
            {
                _dragOverlay.Tapped += this.OnDragOverlayTapped;
                _dragOverlay.ManipulationMode = ManipulationModes.TranslateX | ManipulationModes.TranslateY;
                _dragOverlay.PointerPressed += this.OnDragOverlayPointerPressed;
                _dragOverlay.PointerReleased += this.OnDragOverlayPointerReleased;
                _dragOverlay.PointerCaptureLost += this.OnDragOverlayPointerCaptureLost;
            }

            if (_decrementButton != null)
            {
                _decrementButton.Click += this.OnDecrementButtonClick;
                var pcc =
                    new PropertyChangeEventSource<bool>
                        (_decrementButton, "IsPressed");
                pcc.ValueChanged += this.OnDecrementButtonIsPressedChanged;
            }

            if (_incrementButton != null)
            {
                _incrementButton.Click += this.OnIncrementButtonClick;
                var pcc =
                    new PropertyChangeEventSource<bool>
                        (_incrementButton, "IsPressed");
                pcc.ValueChanged += this.OnIncrementButtonIsPressedChanged;
            }

            if (_valueBar != null)
            {
                _valueBar.SizeChanged += this.OnValueBarSizeChanged;

                this.UpdateValueBar();
            }

            this.UpdateIsReadOnlyDependants();
            this.SetValidIncrementDirection();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Invoked whenever application code or internal processes (such as a rebuilding layout pass) call ApplyTemplate. In simplest terms, this means the method is called just before a UI element displays in your app. Override this method to influence the default post-template logic of a class.
        /// </summary>
        protected override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            if (DesignMode.DesignModeEnabled)
            {
                return;
            }

            this.GotFocus            += OnGotFocus;
            this.LostFocus           += OnLostFocus;
            this.PointerWheelChanged += OnPointerWheelChanged;
            _valueTextBox             = GetTemplateChild(ValueTextBoxName) as UpDownTextBox;
            _dragOverlay              = GetTemplateChild(DragOverlayName) as UIElement;
            _decrementButton          = GetTemplateChild(DecrementButtonName) as RepeatButton;
            _incrementButton          = GetTemplateChild(IncrementButtonName) as RepeatButton;
            _valueBar = GetTemplateChild(ValueBarName) as FrameworkElement;

            if (_valueTextBox != null)
            {
                _valueTextBox.LostFocus     += OnValueTextBoxLostFocus;
                _valueTextBox.GotFocus      += OnValueTextBoxGotFocus;
                _valueTextBox.Text           = Value.ToString();
                _valueTextBox.TextChanged   += OnValueTextBoxTextChanged;
                _valueTextBox.KeyDown       += OnValueTextBoxKeyDown;
                _valueTextBox.UpPressed     += (s, e) => this.Increment();
                _valueTextBox.DownPressed   += (s, e) => this.Decrement();
                _valueTextBox.PointerExited += OnValueTextBoxPointerExited;
            }

            if (_dragOverlay != null)
            {
                _dragOverlay.Tapped             += OnDragOverlayTapped;
                _dragOverlay.ManipulationMode    = ManipulationModes.TranslateX | ManipulationModes.TranslateY;
                _dragOverlay.PointerPressed     += OnDragOverlayPointerPressed;
                _dragOverlay.PointerReleased    += OnDragOverlayPointerReleased;
                _dragOverlay.PointerCaptureLost += OnDragOverlayPointerCaptureLost;
            }

            if (_decrementButton != null)
            {
                _decrementButton.Click += OnDecrementButtonClick;
                var pcc =
                    new PropertyChangeEventSource <bool>
                        (_decrementButton, "IsPressed");
                pcc.ValueChanged += OnDecrementButtonIsPressedChanged;
            }

            if (_incrementButton != null)
            {
                _incrementButton.Click += OnIncrementButtonClick;
                var pcc =
                    new PropertyChangeEventSource <bool>
                        (_incrementButton, "IsPressed");
                pcc.ValueChanged += OnIncrementButtonIsPressedChanged;
            }

            if (_valueBar != null)
            {
                _valueBar.SizeChanged += OnValueBarSizeChanged;

                UpdateValueBar();
            }

            UpdateIsReadOnlyDependants();
            SetValidIncrementDirection();
        }
 /// <summary>
 /// Invoked whenever application code or internal processes (such as a rebuilding layout pass) call ApplyTemplate. In simplest terms, this means the method is called just before a UI element displays in your app. Override this method to influence the default post-template logic of a class.
 /// </summary>
 protected override void OnApplyTemplate()
 {
     this.UnsubscribeEvents();
     this.textBox = this.GetTemplateChild(TextBoxPropertyName) as UpDownTextBox;
     this.autoCompletePresenter = this.GetTemplateChild(AutoCompletePresenterPropertyName) as Popup;
     this.autoCompletePresenter.Width = this.ActualWidth;
     this.autocompleteItemsContainer = this.GetTemplateChild(AutocompleteItemsContainerPropertyName) as SimpleThemingListBox;
     this.autocompleteItemsContainer.Width = this.ActualWidth;
     this.SetBorderThickness();
     base.OnApplyTemplate();
     this.SubscribeEvents();
 }