Browse Source

NumericUpDown: implemented new feature request of SelectAllOnGotFocus property. When set to true, all text will be selected when the user tabs or single clicks into the control.

pull/1645/head
brianlagunas_cp 15 years ago
parent
commit
d417961ec2
  1. 37
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/NumericUpDown/NumericUpDown.cs

37
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/NumericUpDown/NumericUpDown.cs

@ -1,6 +1,7 @@
using System;
using System.Windows;
using System.Globalization;
using System.Windows.Input;
namespace Microsoft.Windows.Controls
{
@ -75,6 +76,17 @@ namespace Microsoft.Windows.Controls
#endregion //FormatString
#region SelectAllOnGotFocus
public static readonly DependencyProperty SelectAllOnGotFocusProperty = DependencyProperty.Register("SelectAllOnGotFocus", typeof(bool), typeof(NumericUpDown), new PropertyMetadata(false));
public bool SelectAllOnGotFocus
{
get { return (bool)GetValue(SelectAllOnGotFocusProperty); }
set { SetValue(SelectAllOnGotFocusProperty, value); }
}
#endregion //SelectAllOnGotFocus
#endregion
#region Constructors
@ -94,6 +106,13 @@ namespace Microsoft.Windows.Controls
{
base.OnApplyTemplate();
SetValidSpinDirection();
if (SelectAllOnGotFocus)
{
//in order to select all the text we must handle both the keybord (tabbing) and mouse (clicking) events
TextBox.GotKeyboardFocus += OnTextBoxGotKeyBoardFocus;
TextBox.PreviewMouseLeftButtonDown += OnTextBoxPreviewMouseLeftButtonDown;
}
}
protected override void OnValueChanged(object oldValue, object newValue)
@ -160,6 +179,24 @@ namespace Microsoft.Windows.Controls
#endregion //Base Class Overrides
#region Event Handlers
private void OnTextBoxGotKeyBoardFocus(object sender, RoutedEventArgs e)
{
TextBox.SelectAll();
}
void OnTextBoxPreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (!TextBox.IsKeyboardFocused)
{
e.Handled = true;
TextBox.Focus();
}
}
#endregion //Event Handlers
#region Methods
/// <summary>

Loading…
Cancel
Save