Thankyou that worked.
I created it as an attached property to the numericupdown control with a minor change to the Box_PointerReleased event using (sender as SfTextBoxExt).SelectAll();
Thanks for your help
Here is my Attached property class
public static class NumericUpDownAttached
{
public static bool GetAutoSelectable(DependencyObject obj)
{
return (bool)obj.GetValue(AutoSelectableProperty);
}
public static void SetAutoSelectable(DependencyObject obj, bool value)
{
obj.SetValue(AutoSelectableProperty, value);
}
public static readonly DependencyProperty AutoSelectableProperty =
DependencyProperty.RegisterAttached(
"AutoSelectable",
typeof(bool),
typeof(TextBoxAttached),
new PropertyMetadata(false, AutoFocusableChangedHandler));
private static void AutoFocusableChangedHandler(
DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (e.NewValue != e.OldValue)
{
if ((bool)e.NewValue == true)
{
(d as SfNumericUpDown).Loaded += numericupdown_Loaded;
(d as SfNumericUpDown).LostFocus += NumericUpDownAttached_LostFocus;
}
else
{
(d as SfNumericUpDown).Loaded -= numericupdown_Loaded;
(d as SfNumericUpDown).LostFocus -= NumericUpDownAttached_LostFocus;
}
}
}
static bool isfocused = false;
private static void NumericUpDownAttached_LostFocus(object sender, RoutedEventArgs e)
{
isfocused = true;
}
static SfNumericTextBox sfNumericTextBox;
private static void numericupdown_Loaded(object sender, RoutedEventArgs e)
{
FindChildren<SfNumericTextBox>((sender as SfNumericUpDown));
}
public static void FindChildren<T>(DependencyObject startNode)
{
int count = VisualTreeHelper.GetChildrenCount(startNode);
for (int i = 0; i < count; i++)
{
DependencyObject current = VisualTreeHelper.GetChild(startNode, i);
if (current is SfNumericTextBox)
{
sfNumericTextBox = current as SfNumericTextBox;
sfNumericTextBox.AddHandler(SfTextBoxExt.PointerReleasedEvent, new PointerEventHandler(Box_PointerReleased), true);
break;
}
else
{
FindChildren<T>(current);
}
}
}
private static void Box_PointerReleased(object sender, PointerRoutedEventArgs e)
{
if (isfocused)
{
(sender as SfTextBoxExt).SelectAll();
isfocused = false;
}
}
}
and xaml usage
<Input:SfNumericUpDown LargeChange="5" MaximumNumberDecimalDigits="1" Minimum="1" Maximum="50" FormatString="0" Common:NumericUpDownAttached.AutoSelectable="True" />