)
We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to select entire text in SfMaskedEdit on getting focused?

Platform: WPF |
Control: SfMaskedEdit |
Published Date: February 24, 2016 |
Last Revised Date: June 25, 2019 |
Product Version: 13.4.0.53

To select entire text on MaskedEdit when it got focus, a dependency Boolean property have implemented called IsSelectAllOnFocus. When the IsSelectAllOnFocus property is True, the whole text of the MaskedEdit control will get select. The same has been demonstrated in the following code example:

XAML:

<Window x:Class="MaskedEdit_Behavior.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525"
xmlns:local="clr-namespace:MaskedEdit_Behavior"
xmlns:syncfusion="http://schemas.syncfusion.com/wpf">
<Grid>
<StackPanel>
<TextBlock Text="MaskedEditExt "/>
<local:MaskedEditExt Height="28" Width="180" Margin="0 10 0 0" Text="Test"
IsSelectAllOnFocus="true"/>
</StackPanel>
</Grid>
</Window>

 

C#:

namespace MaskedEdit_Behavior
{
public class MaskedEditExt:SfMaskedEdit
{
public bool IsSelectAllOnFocus
{
get { return (bool)GetValue(IsSelectAllOnFocusProperty); }
set { SetValue(IsSelectAllOnFocusProperty, value); }
}
 
// Using a DependencyProperty as the backing store for IsSelectAllOnFocus.  This enables animation, styling, binding, etc...
public static readonly DependencyProperty IsSelectAllOnFocusProperty =
DependencyProperty.Register("IsSelectAllOnFocus", typeof(bool), typeof(MaskedEditExt), new PropertyMetadata(false));
 
protected override void OnGotFocus(System.Windows.RoutedEventArgs e)
{
base.OnGotFocus(e);
if (IsSelectAllOnFocus)
SelectAll();
}
 
protected override void OnPreviewMouseDown(System.Windows.Input.MouseButtonEventArgs e)
{
if (IsSelectAllOnFocus)
{
if (IsKeyboardFocusWithin)
return;
e.Handled = true;
Focus();
}
else
base.OnPreviewMouseDown(e);
}
}
}
 

 

2X faster development

The ultimate WPF UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon