Completed
Last Updated: 11 Oct 2023 08:02 by ADMIN
Release 6.3.0
Teddy
Created on: 07 Nov 2022 16:43
Category: UI for .NET MAUI
Type: Feature Request
4
Add SelectionOnFocus to RadEntry
Your WPF input controls have a SelectionOnFocus enum that describes the behavior when a user gives focus to one of those controls. Can that functionality be added to RadEntry in MAUI?

In addition, as a workaround, I tried adding this code to a RadEntry's Focused event to try to select all text:
private void OnEntryFocused(object sender, FocusEventArgs e)
{
    if (sender is RadEntry entry && !string.IsNullOrEmpty(entry.Text))
    {
        entry.CursorPosition = 0;
        entry.SelectionLength = entry.Text.Length;
    }
}
With this code, the first time I click into the entry, it selects all text as expected, but then when I click out of it and click in again, it doesn't select all text. It just places the caret where I clicked. Then I click out and click back in again and it selects all the text, then the next time, it doesn't work. So it goes back and forth between selecting all text and placing the caret where I clicked.
1 comment
ADMIN
Antoan
Posted on: 11 Nov 2022 16:14

Hello Theodoros,

Thank you for your interest in Telerik UI for .NET Maui.

I talked with the devs and they agree this is a useful feature. Therefore, I have updated this feature request from Under Review to Unplanned. We'll update the status again if it goes on the roadmap or we jump right to development.

Workaround:

Regarding a workaround your solution is correct, however due to the nature of Maui UI you wont see the change if there isn't something which will update the UI. In this case you may use a Dispatcher, the following code should fix the selection:

private void OnEntryFocused(object sender, FocusEventArgs e)
        {
            
            this.Dispatcher.StartTimer(TimeSpan.FromMilliseconds(20), () =>
            {
                if (sender is RadEntry entry && !string.IsNullOrEmpty(entry.Text))
                {
                    entry.CursorPosition = 0;
                    entry.SelectionLength = entry.Text.Length;
                }
                return false;
            });
        }

Regards,
Antoan
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.