If I have a string value that represents a decimal number (e.g. "15.123") the current default double click behavior is to select only the text before or after the decimal. How can I change this to select all text in the field on double click?
2 Answers, 1 is accepted
0
Dinko | Tech Support Engineer
Telerik team
answered on 24 Jan 2018, 12:42 PM
Hi Karl,
A possible approach which you can try is to use the EventManager.RegisterClassHandler() method to subscribe to the MouseDoubleClickEvent of the TextBoxes. In the event handler, you can get the TextBox and called its SelectAll() method which selects all the text. Check the following code snippet.
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
EventManager.RegisterClassHandler(typeof(TextBox), TextBox.MouseDoubleClickEvent, new RoutedEventHandler(OnMouseDoubleClickEvent));
Give this approach a try and let me know if it works in your main application.
Regards,
Dinko
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
While the EventManager solution appears to work, I was concerned about using it in our application after reading about possible memory leak issues if used incorrectly.
I then realized we can achieve this with a style EventSetter: