Skip to content

Commit 198a197

Browse files
author
roubachof
committed
fix(winUI): fix margin not being applied
1 parent 41c028b commit 198a197

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

Maui.Shadows/Platforms/Windows/ShadowsHandler.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Microsoft.Maui.Handlers;
22
using Microsoft.Maui.Platform;
3+
using Microsoft.UI.Xaml;
34
using Microsoft.UI.Xaml.Controls;
45
using Grid = Microsoft.UI.Xaml.Controls.Grid;
56

@@ -17,6 +18,7 @@ public class ShadowsHandler : ViewHandler<Shadows, Grid>
1718

1819
private WindowsShadowsController? _shadowsController;
1920
private Canvas? _shadowsCanvas;
21+
private FrameworkElement? _contentPlatformView;
2022

2123
public ShadowsHandler() : base(ShadowsMapper)
2224
{
@@ -64,11 +66,20 @@ protected override void ConnectHandler(Grid platformView)
6466
// Create and add content view
6567
if (shadowsView.Content != null)
6668
{
67-
var contentView = shadowsView.Content.ToPlatform(MauiContext!);
68-
platformView.Children.Add(contentView);
69+
_contentPlatformView = shadowsView.Content.ToPlatform(MauiContext!);
70+
71+
// Manually apply MAUI margin to the platform view
72+
var contentMargin = shadowsView.Content.Margin;
73+
_contentPlatformView.Margin = new Microsoft.UI.Xaml.Thickness(
74+
contentMargin.Left,
75+
contentMargin.Top,
76+
contentMargin.Right,
77+
contentMargin.Bottom);
78+
79+
platformView.Children.Add(_contentPlatformView);
6980

7081
// Create shadow controller
71-
_shadowsController = new WindowsShadowsController(_shadowsCanvas, contentView, shadowsView.CornerRadius);
82+
_shadowsController = new WindowsShadowsController(_shadowsCanvas, _contentPlatformView, shadowsView.CornerRadius);
7283
_shadowsController.UpdateShades(shadowsView.Shades);
7384

7485
// Subscribe to collection changes
@@ -97,6 +108,7 @@ protected override void DisconnectHandler(Grid platformView)
97108
// Clear platform view children
98109
platformView.Children.Clear();
99110
_shadowsCanvas = null;
111+
_contentPlatformView = null;
100112

101113
_instanceCount--;
102114
InternalLogger.Debug(_tag, () => $"Disposed => {_instanceCount} instances");

0 commit comments

Comments
 (0)