Change Text Highlighting When RadEntry is Focused

1 Answer 53 Views
Entry
Nelson
Top achievements
Rank 1
Nelson asked on 17 Oct 2023, 09:34 AM
Hi, is there a way to change the color of the text highlighting when a RadEntry is focused? Currently, we need this feature for our project.

1 Answer, 1 is accepted

Sort by
0
Yana
Telerik team
answered on 20 Oct 2023, 09:22 AM | edited on 23 Oct 2023, 11:56 AM

Hello Nelson,

Text highlighting is platform-specific and comes from the .NET MAUI Entry default styles on different platforms.  For example on Windows you would need to add the styles inside Platforms/Windows.App.xaml file.

I came across the other discussion on Entry styles here: Style for disabled RadEntry is not working, so you just need to add the following setter of the SelectionHighlightColor inside the MaskedEntryControlTextBoxStyle style:

 

<Style x:Key="MaskedEntryControlTextBoxStyle" TargetType="TextBox" BasedOn="{StaticResource DefaultTextBoxStyle}">
    <Setter Property="SelectionHighlightColor" Value="Green" />
        <Setter Property="Template">
....

 

I hope this would help.

Regards,
Yana
Progress Telerik

A brand new .NET MAUI course was just added to the Virtual Classroom. The training course is developed to help you get started with the Telerik UI for .NET MAUI components and features. It aims to put you in the shoes of an engineer who adds new features to an existing application. You can check it out at https://learn.telerik.com
Nelson
Top achievements
Rank 1
commented on 20 Oct 2023, 10:49 AM

Hi,

Thank you for this. Is it possible to apply this style to a specific entry only? 

Yana
Telerik team
commented on 23 Oct 2023, 02:32 PM

Hi Nelson,

If you need to apply a different selection highlight color to one RadEntry instance, you can create a custom class which inherits from RadEntry and override its OnHandlerChanged() method. In it you can get a reference to the Windows TextBox through the InputEditor property and assign its SelectionHighlightColor, here is a quick sample:

 

public class MyRadEntry : RadEntry
{
    protected override void OnHandlerChanged()
    {
        base.OnHandlerChanged();

        // Step 1. Make sure the PlatformView is available
        if (this.Handler?.PlatformView is RadMauiEntry nativeEntry)
        {
            // Step 2. change the desired native-specific properties
#if WINDOWS
            nativeEntry.Loaded += (s, a) =>
            {
                Microsoft.UI.Xaml.Controls.TextBox tb = nativeEntry.InputEditor;
                tb.SelectionHighlightColor = new Microsoft.UI.Xaml.Media.SolidColorBrush(Windows.UI.Color.FromArgb(255, 255, 0, 0));
            };
#endif
        }
    }
}

 

Then you can add the MyRadEntry to the page:

<local:MyRadEntry Text="custom rad entry text" />

I hope this would be of help.

Tags
Entry
Asked by
Nelson
Top achievements
Rank 1
Answers by
Yana
Telerik team
Share this question
or