.NET MAUI BorderLessEntry for all platforms

vamsi_reddy_397438ed17335

Vamsi Reddy

Posted on March 21, 2024

.NET MAUI BorderLessEntry for all platforms

Image description

First Create a Class with BorderlessEntry and add the below code

public class BorderlessEntry: Entry

{
}

Next in the MauiProgram.cs file add the below line of code

public static MauiApp CreateMauiApp()

    {
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
});
    Microsoft.Maui.Handlers.EntryHandler.Mapper.AppendToMapping("Borderless",(handler,view) =&gt;
    {
        if(view is BorderlessEntry)
        {
Enter fullscreen mode Exit fullscreen mode
Enter fullscreen mode Exit fullscreen mode




if ANDROID


           handler.PlatformView.Background=null;
handler.PlatformView.SetBackgroundColor(Android.Graphics.Color.Transparent);
Enter fullscreen mode Exit fullscreen mode




elif IOS || MACCATALYST


                handler.PlatformView.BackgroundColor = UIKit.UIColor.Clear;
handler.PlatformView.Layer.BorderWidth= 0;
handler.PlatformView.BorderStyle = UIKit.UITextBorderStyle.None;
Enter fullscreen mode Exit fullscreen mode




elif WINDOWS


                 handler.PlatformView.BorderThickness= new Microsoft.UI.Xaml.Thickness(0);
Enter fullscreen mode Exit fullscreen mode




endif


            }
    });
    return builder.Build();
}
Enter fullscreen mode Exit fullscreen mode
Enter fullscreen mode Exit fullscreen mode




final in Solution Explore open Platforms/Windows/App. Xaml and add the below line of code

<maui: MauiWinUIApplication.Resources>
<Thickness x:Key="TextControlBorderThemeThickness">0</Thickness>
<Thickness x:Key="TextControlBorderThemeThicknessFocused">0</Thickness>
</maui: MauiWinUIApplication.Resources>

💖 💪 🙅 🚩
vamsi_reddy_397438ed17335
Vamsi Reddy

Posted on March 21, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related