DEV Community

Vamsi Reddy
Vamsi Reddy

Posted on

1 1 1 1 1

.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>

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (1)

Collapse
 
andersonpull profile image
Anderson Oliveira Bezerra

Very good, congratulations on the content.

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs