From 75f3e3541b096ebd8de2b212d5edb71672d08b6c Mon Sep 17 00:00:00 2001 From: parham saremi <45370204+parhamsaremi@users.noreply.github.com> Date: Wed, 29 Mar 2023 12:10:25 +0330 Subject: [PATCH] Controls.Hosting(GTK): mappings for Frame (#11) Add mappers for BorderColor and CornerRadius for Frame elements so they can now have borders. --- .../Xaml/Hosting/AppHostBuilderExtensions.cs | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/Controls/src/Xaml/Hosting/AppHostBuilderExtensions.cs b/src/Controls/src/Xaml/Hosting/AppHostBuilderExtensions.cs index ab6553a13208..13e717c1ffe1 100644 --- a/src/Controls/src/Xaml/Hosting/AppHostBuilderExtensions.cs +++ b/src/Controls/src/Xaml/Hosting/AppHostBuilderExtensions.cs @@ -26,6 +26,7 @@ #elif GTK using Microsoft.Maui.Controls.Handlers.Compatibility; using Microsoft.Maui.Controls.Compatibility.Platform.Gtk; +using Microsoft.Maui.Graphics.Platform.Gtk; #endif namespace Microsoft.Maui.Controls.Hosting @@ -181,6 +182,7 @@ static MauiAppBuilder SetupDefaults(this MauiAppBuilder builder) builder.Services.TryAddEnumerable(ServiceDescriptor.Transient()); #endif builder.RemapForControls(); + AddDefaultMappings(); return builder; } @@ -249,5 +251,34 @@ internal static MauiAppBuilder RemapForControls(this MauiAppBuilder builder) return builder; } + + internal static void AddDefaultMappings() + { +#if GTK + ContentViewHandler.Mapper.AppendToMapping( + "BorderColor", + (IContentViewHandler handler, IContentView view) => + { + if (view is Frame frame) + { + Microsoft.Maui.Platform.ContentView contentView = (Microsoft.Maui.Platform.ContentView)handler.PlatformView; + contentView.SetStyleValueNode($"1px solid {frame.BorderColor.ToGdkRgba().ToString()}", contentView.CssMainNode(), "border"); + } + } + ); + + ContentViewHandler.Mapper.AppendToMapping( + "CornerRadius", + (IContentViewHandler handler, IContentView view) => + { + if (view is Frame frame) + { + Microsoft.Maui.Platform.ContentView contentView = (Microsoft.Maui.Platform.ContentView)handler.PlatformView; + contentView.SetStyleValueNode($"{frame.CornerRadius:f}px", contentView.CssMainNode(), "border-radius"); + } + } + ); +#endif + } } } \ No newline at end of file