In my .NET MAUI Entry, I wanted to change the Color of the Underline in an Entry in Code-Behind.
Is there a way to do this?
======= Edited with implementation of Answer below ======
Hint: I tried the answer below with an own BorderlessEntryControl which was derived from an Entry Control. There, at least the Placehodler-TextColor got lost. Maybe more Properties
Before
After
For remove the underline on the android, you can add the following code into the MauiProgram.cs:
Microsoft.Maui.Handlers.EntryHandler.Mapper.AppendToMapping(nameof(Entry), (handler, view) =>
{
#if ANDROID
handler.PlatformView.SetBackgroundColor(Android.Graphics.Color.Transparent);
#endif
});
And on the windows platform, you can put the following code into the /Platforms/Windows/App.xaml:
<maui:MauiWinUIApplication.Resources>
<Thickness x:Key="TextControlBorderThemeThickness">0</Thickness>
<Thickness x:Key="TextControlBorderThemeThicknessFocused">0</Thickness>
</maui:MauiWinUIApplication.Resources>
And there is no underline on the ios.
update 1:
Before:
After: