-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
WindowHandler.Windows.cs
73 lines (60 loc) · 2.54 KB
/
WindowHandler.Windows.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using System;
using Microsoft.UI.Xaml.Controls;
namespace Microsoft.Maui.Handlers
{
public partial class WindowHandler : ElementHandler<IWindow, UI.Xaml.Window>
{
protected override void DisconnectHandler(UI.Xaml.Window platformView)
{
MauiContext
?.GetNavigationRootManager()
?.Disconnect();
platformView.Content = null;
base.DisconnectHandler(platformView);
}
public static void MapTitle(IWindowHandler handler, IWindow window) =>
handler.PlatformView?.UpdateTitle(window);
public static void MapContent(IWindowHandler handler, IWindow window)
{
_ = handler.MauiContext ?? throw new InvalidOperationException($"{nameof(MauiContext)} should have been set by base class.");
var windowManager = handler.MauiContext.GetNavigationRootManager();
windowManager.Disconnect();
windowManager.Connect(handler.VirtualView.Content.ToPlatform(handler.MauiContext));
handler.PlatformView.Content = windowManager.RootView;
if (window.VisualDiagnosticsOverlay != null)
window.VisualDiagnosticsOverlay.Initialize();
}
public static void MapToolbar(IWindowHandler handler, IWindow view)
{
if (view is IToolbarElement tb)
ViewHandler.MapToolbar(handler, tb);
}
public static void MapMenuBar(IWindowHandler handler, IWindow view)
{
if (view is IMenuBarElement mb)
{
_ = handler.MauiContext ?? throw new InvalidOperationException($"{nameof(MauiContext)} should have been set by base class.");
var windowManager = handler.MauiContext.GetNavigationRootManager();
windowManager.SetMenuBar(mb.MenuBar?.ToPlatform(handler.MauiContext!) as MenuBar);
}
}
public static void MapFlowDirection(IWindowHandler handler, IWindow view)
{
var WindowHandle = handler.PlatformView.GetWindowHandle();
// Retrieve current extended style
var extended_style = PlatformMethods.GetWindowLongPtr(WindowHandle, PlatformMethods.WindowLongFlags.GWL_EXSTYLE);
long updated_style;
if (view.FlowDirection == FlowDirection.RightToLeft)
updated_style = extended_style | (long)PlatformMethods.ExtendedWindowStyles.WS_EX_LAYOUTRTL;
else
updated_style = extended_style & ~((long)PlatformMethods.ExtendedWindowStyles.WS_EX_LAYOUTRTL);
if (updated_style != extended_style)
PlatformMethods.SetWindowLongPtr(WindowHandle, PlatformMethods.WindowLongFlags.GWL_EXSTYLE, updated_style);
}
public static void MapRequestDisplayDensity(IWindowHandler handler, IWindow window, object? args)
{
if (args is DisplayDensityRequest request)
request.SetResult(handler.PlatformView.GetDisplayDensity());
}
}
}