/// <summary>
        /// The template gets added to the control.
        /// </summary>
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            _textBox = GetTemplateChild("PART_TextBox") as TextBox;
            if (_textBox == null)
            {
                return;
            }

            _upButton = GetTemplateChild("PART_UpButton") as RepeatButton;
            if (_upButton != null)
            {
                _upButton.Click += HandleUpClick;
            }

            _downButton = GetTemplateChild("PART_DownButton") as RepeatButton;
            if (_downButton != null)
            {
                _downButton.Click += HandleDownClick;
            }

            _resetButton = GetTemplateChild("PART_ResetButton") as Button;
            if (_resetButton != null)
            {
                _resetButton.Click += HandleResetClick;
            }

            _number.Initialize(Number, Minimum, Maximum, Step, DefaultNumber, InputCulture, PredefinesCulture);
            _textBox.Text = _number.ToString();

            _textBox.PreviewKeyDown   += HandleTextBoxPreviewKeyDown;
            _textBox.PreviewTextInput += HandlePreviewTextInput;
            _textBox.CommandBindings.Add(new CommandBinding(ApplicationCommands.Paste, null, CanPasteCommand));
            _textBox.GotFocus  += HandleTextBoxGotFocus;
            _textBox.LostFocus += HandleTextBoxLostFocus;

            EnableDisableUpDownButtons();
        }
 private void OnNumberTypeChanged(DependencyPropertyChangedEventArgs e)
 {
     _number = NumberFactory.Create((NumberType)e.NewValue);
     _number.Initialize(Number, Minimum, Maximum, Step, DefaultNumber, InputCulture, PredefinesCulture);
 }