Skip to content

Commit 1bd2555

Browse files
committed
fix: LayoutSlotWithMarginsAndAlignments is not correct on WASM due to BorderThickness
1 parent 350d8bc commit 1bd2555

File tree

2 files changed

+50
-7
lines changed

2 files changed

+50
-7
lines changed

src/Uno.UI/UI/Xaml/FrameworkElementExtensions.cs

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,48 @@ internal static bool TrySetPadding(this IFrameworkElement frameworkElement, Thic
324324
return false;
325325
}
326326

327+
internal static bool TryGetActualBorderThickness(this IFrameworkElement frameworkElement, out Thickness borderThickness)
328+
{
329+
if (__LinkerHints.Is_Windows_UI_Xaml_Controls_Grid_Available && frameworkElement is Grid g)
330+
{
331+
borderThickness = g.BorderThickness;
332+
return true;
333+
}
334+
335+
if (__LinkerHints.Is_Windows_UI_Xaml_Controls_StackPanel_Available && frameworkElement is StackPanel sp)
336+
{
337+
borderThickness = sp.BorderThickness;
338+
return true;
339+
}
340+
341+
if (__LinkerHints.Is_Windows_UI_Xaml_Controls_RelativePanel_Available && frameworkElement is RelativePanel rp)
342+
{
343+
borderThickness = rp.BorderThickness;
344+
return true;
345+
}
346+
347+
if (__LinkerHints.Is_Microsoft_UI_Xaml_Controls_LayoutPanel_Available && frameworkElement is Microsoft.UI.Xaml.Controls.LayoutPanel lp)
348+
{
349+
borderThickness = lp.BorderThickness;
350+
return true;
351+
}
352+
353+
if (__LinkerHints.Is_Windows_UI_Xaml_Controls_ContentPresenter_Available && frameworkElement is ContentPresenter cp)
354+
{
355+
borderThickness = cp.BorderThickness;
356+
return true;
357+
}
358+
359+
if (__LinkerHints.Is_Windows_UI_Xaml_Controls_Border_Available && frameworkElement is Border b)
360+
{
361+
borderThickness = b.BorderThickness;
362+
return true;
363+
}
364+
365+
borderThickness = default;
366+
return false;
367+
}
368+
327369
internal static bool TryGetBorderThickness(this IFrameworkElement frameworkElement, out Thickness borderThickness)
328370
{
329371
if (__LinkerHints.Is_Windows_UI_Xaml_Controls_Grid_Available && frameworkElement is Grid g)
@@ -368,12 +410,6 @@ internal static bool TryGetBorderThickness(this IFrameworkElement frameworkEleme
368410
return true;
369411
}
370412

371-
if (__LinkerHints.Is_Windows_UI_Xaml_Controls_CalendarViewBaseItem_Available && frameworkElement is CalendarViewBaseItem cbi)
372-
{
373-
borderThickness = cbi.GetItemBorderThickness();
374-
return true;
375-
}
376-
377413
borderThickness = default;
378414
return false;
379415
}

src/Uno.UI/UI/Xaml/UIElement.wasm.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,14 @@ protected internal void SetClasses(string[] cssClasses, int index = -1)
219219
/// <param name="clipRect">The Clip rect to set, if any</param>
220220
protected internal void ArrangeVisual(Rect rect, Rect? clipRect)
221221
{
222-
LayoutSlotWithMarginsAndAlignments = rect;
222+
// FrameworkElement.ArrangeElement shifts the origin by border thickness to adhere to HTML's behavior,
223+
// for LayoutSlotWithMarginsAndAlignments we need to shift it back in the right place for consistency
224+
// with other platforms.
225+
LayoutSlotWithMarginsAndAlignments =
226+
VisualTreeHelper.GetParent(this) is FrameworkElement parent &&
227+
parent.TryGetActualBorderThickness(out var borderThickness)
228+
? new Rect(rect.X + borderThickness.Left, rect.Y + borderThickness.Top, rect.Width, rect.Height)
229+
: rect;
223230

224231
if (FeatureConfiguration.UIElement.AssignDOMXamlProperties)
225232
{

0 commit comments

Comments
 (0)