Skip to content

Commit 601a208

Browse files
committed
feat: Xaml Island root
1 parent 0246f3e commit 601a208

File tree

3 files changed

+52
-3
lines changed

3 files changed

+52
-3
lines changed

src/Uno.UI/UI/Xaml/Hosting/DesktopWindowXamlSource.cs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,33 @@
1-
namespace Windows.UI.Xaml.Hosting;
1+
using Uno.UI.Xaml.Core;
2+
using Uno.UI.Xaml.Islands;
3+
using Windows.UI.Xaml.Controls;
4+
5+
namespace Windows.UI.Xaml.Hosting;
26

37
public partial class DesktopWindowXamlSource : global::System.IDisposable
48
{
5-
public global::Windows.UI.Xaml.UIElement Content { get; set; }
9+
private XamlIslandRoot _root;
10+
11+
public global::Windows.UI.Xaml.UIElement Content
12+
{
13+
get => _root?.ContentRoot.VisualTree.PublicRootVisual;
14+
set
15+
{
16+
if (_root is null)
17+
{
18+
_root = new XamlIslandRoot(CoreServices.Instance);
19+
}
20+
_root.SetPublicRootVisual(value);
21+
}
22+
}
623

724
public bool HasFocus => false;
825

926
public DesktopWindowXamlSource()
1027
{
11-
global::Windows.Foundation.Metadata.ApiInformation.TryRaiseNotImplemented("Windows.UI.Xaml.Hosting.DesktopWindowXamlSource", "DesktopWindowXamlSource.DesktopWindowXamlSource()");
28+
1229
}
30+
1331
public global::Windows.UI.Xaml.Hosting.XamlSourceFocusNavigationResult NavigateFocus(global::Windows.UI.Xaml.Hosting.XamlSourceFocusNavigationRequest request)
1432
{
1533
return null;

src/Uno.UI/UI/Xaml/Internal/CoreServices.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ internal void PutVisualRoot(DependencyObject? dependencyObject)
6262

6363
// Set the root visual from the parser result. If we're passed null it means
6464
// we're supposed to just clear the tree.
65+
// TODO: This is not currently happening, adjust when porting next time
6566
if (dependencyObject != null)
6667
{
6768
var root = dependencyObject as UIElement;
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using Uno.UI.Xaml.Core;
2+
using Windows.UI;
3+
using Windows.UI.Xaml;
4+
using Windows.UI.Xaml.Controls;
5+
6+
namespace Uno.UI.Xaml.Islands;
7+
8+
internal class XamlIslandRoot : Panel
9+
{
10+
private readonly ContentRoot _contentRoot;
11+
12+
internal XamlIslandRoot(CoreServices coreServices)
13+
{
14+
_contentRoot = coreServices.ContentRootCoordinator.CreateContentRoot(ContentRootType.XamlIsland, Colors.Transparent, this);
15+
16+
//Uno specific - flag as VisualTreeRoot for interop with existing logic
17+
IsVisualTreeRoot = true;
18+
}
19+
20+
internal ContentRoot ContentRoot => _contentRoot;
21+
22+
internal void SetPublicRootVisual(UIElement uiElement)
23+
{
24+
_contentRoot.VisualTree.SetPublicRootVisual(uiElement, null, null);
25+
26+
UIElement.LoadingRootElement(uiElement);
27+
28+
UIElement.RootElementLoaded(uiElement);
29+
}
30+
}

0 commit comments

Comments
 (0)