Skip to content

Commit

Permalink
fix: load XamlRoot RootElement in UnoIslands
Browse files Browse the repository at this point in the history
  • Loading branch information
ramezgerges authored and MartinZikmund committed Jan 19, 2024
1 parent dfde9b3 commit a354c42
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 30 deletions.
25 changes: 2 additions & 23 deletions src/Uno.UI.XamlHost.Skia.Wpf/UnoXamlHostBase.Layout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ protected override Size MeasureOverride(Size constraint)

if (IsXamlContentLoaded())
{
_xamlSource.Content.Measure(new Windows.Foundation.Size(constraint.Width, constraint.Height));
_xamlSource.XamlIsland.Measure(new Windows.Foundation.Size(constraint.Width, constraint.Height));
desiredSize.Width = _xamlSource.Content.DesiredSize.Width;
desiredSize.Height = _xamlSource.Content.DesiredSize.Height;
}
Expand All @@ -50,7 +50,7 @@ protected override Size ArrangeOverride(Size finalSize)
// set to 'Stretch'. The UWP XAML content will be 0 in the stretch alignment direction
// until Arrange is called, and the UWP XAML content is expanded to fill the available space.
var finalRect = new Windows.Foundation.Rect(0, 0, finalSize.Width, finalSize.Height);
_xamlSource.Content.Arrange(finalRect);
_xamlSource.XamlIsland.Arrange(finalRect);
}

return base.ArrangeOverride(finalSize);
Expand Down Expand Up @@ -87,26 +87,5 @@ private void XamlContentSizeChanged(object sender, WUX.SizeChangedEventArgs e)
{
InvalidateMeasure();
}

private void OnSizeChanged(object sender, System.Windows.SizeChangedEventArgs e)
{
UpdateUnoSize();
}

//TODO: This is temporary workaround, should not be needed as per UWP islands. https://github.com/unoplatform/uno/issues/8978
//Might be some missing logic. Maybe not needed now after Arrange and Measure works with XamlIslandRoot
private void UpdateUnoSize()
{
if (IsXamlContentLoaded())
{
if (_xamlSource.GetVisualTreeRoot() is WUX.FrameworkElement element)
{
var width = ActualWidth;
var height = ActualHeight;
element.Width = width;
element.Height = height;
}
}
}
}
}
4 changes: 0 additions & 4 deletions src/Uno.UI.XamlHost.Skia.Wpf/UnoXamlHostBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,6 @@ public UnoXamlHostBase()

// Hook DesktopWindowXamlSource OnTakeFocus event for Focus processing
_xamlSource.TakeFocusRequested += OnTakeFocusRequested;

SizeChanged += OnSizeChanged;
}

/// <summary>
Expand Down Expand Up @@ -248,8 +246,6 @@ protected WUX.UIElement ChildInternal

// Fire updated event
ChildChanged?.Invoke(this, new EventArgs());

UpdateUnoSize();
}
}

Expand Down
7 changes: 6 additions & 1 deletion src/Uno.UI/UI/Xaml/Hosting/DesktopWindowXamlSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System;
using Uno.UI.Xaml.Islands;
using Windows.Foundation;
using Uno.UI.Xaml.Controls;
using WinUICoreServices = global::Uno.UI.Xaml.Core.CoreServices;

namespace Microsoft.UI.Xaml.Hosting;
Expand Down Expand Up @@ -49,7 +50,11 @@ public DesktopWindowXamlSource()
public UIElement Content
{
get => _xamlIsland.Content;
set => _xamlIsland.Content = value;
set
{
_xamlIsland.Content = value;
ContentManager.TryLoadRootVisual(_xamlIsland.XamlRoot!);
}
}

internal XamlIsland XamlIsland => _xamlIsland;
Expand Down
2 changes: 0 additions & 2 deletions src/Uno.UI/UI/Xaml/Internal/Islands/XamlIsland.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ public UIElement? Content
_contentManager.Content = value;

SetPublicRootVisual(value, null, null);

// TODO:MZ: Islands loading?
}
}

Expand Down

0 comments on commit a354c42

Please sign in to comment.