Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement the basic WindowHandler #1468

Merged
merged 47 commits into from
Jul 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
e82c88a
Initial window handler
mattleibow Jun 27, 2021
542fec0
Get things building
mattleibow Jun 27, 2021
eb13b58
things
mattleibow Jun 28, 2021
23ee1ed
maybe this
mattleibow Jun 28, 2021
0197ba4
that
mattleibow Jun 28, 2021
3bfeb10
Improve that
mattleibow Jun 28, 2021
d48727c
A WIP WIP
mattleibow Jun 28, 2021
cfb583d
Dispose old things
mattleibow Jun 28, 2021
f57af9c
Things
mattleibow Jun 28, 2021
0447097
Add WindowHandler for Windows
mattleibow Jun 28, 2021
dbc7bab
Merge remote-tracking branch 'origin/main' into dev/window-handler
mattleibow Jun 28, 2021
3c5b819
remove that since we get a new handler each time
mattleibow Jun 28, 2021
3fced36
ws
mattleibow Jun 28, 2021
dd2b9ec
Merge remote-tracking branch 'origin/main' into dev/window-handler
mattleibow Jun 28, 2021
09dbbf3
Merge the changed property mapper
mattleibow Jun 28, 2021
a84fdd3
that
mattleibow Jun 29, 2021
7875f1d
Merge remote-tracking branch 'origin/main' into dev/window-handler
mattleibow Jun 29, 2021
e1b0812
Merge remote-tracking branch 'origin/main' into dev/window-handler
mattleibow Jun 29, 2021
ee6a10b
Register the resources in the builder
mattleibow Jun 29, 2021
ba82eb7
undo
mattleibow Jun 29, 2021
8a29e87
Use a better Window lifecycle event
mattleibow Jun 29, 2021
6d6f906
The OfT bust interface the base
mattleibow Jun 29, 2021
99b7e26
tests
mattleibow Jun 29, 2021
bdc62af
no need for SetWindow
mattleibow Jun 29, 2021
96755c2
Merge remote-tracking branch 'origin/main' into dev/window-handler
mattleibow Jun 29, 2021
d97d8ab
Fix things
mattleibow Jun 29, 2021
6e9d821
Merge remote-tracking branch 'origin/main' into dev/window-handler
mattleibow Jun 29, 2021
f6e69ba
use a BP Page
mattleibow Jun 29, 2021
031aad0
Merge remote-tracking branch 'origin/main' into dev/window-handler
mattleibow Jun 29, 2021
a22ea28
Correctly register Windows resource dictionaries
mattleibow Jun 29, 2021
70ff209
Merge branch 'dev/resources' into dev/window-handler
mattleibow Jun 29, 2021
7902f7c
Use handlers...
mattleibow Jun 30, 2021
cfc259b
Handler-ize
mattleibow Jun 30, 2021
b6a9663
iOS things
mattleibow Jun 30, 2021
9f45b84
Merge branch 'dev/window-handler' of github.com:dotnet/Maui into dev/…
mattleibow Jun 30, 2021
742b77f
Merge remote-tracking branch 'origin/main' into dev/window-handler
mattleibow Jun 30, 2021
0293bbc
Merge branch 'dev/window-handler' of https://github.com/dotnet/maui i…
mattleibow Jun 30, 2021
052ba5b
undo tests
mattleibow Jun 30, 2021
e6bf02b
tests
mattleibow Jun 30, 2021
e27b1f6
Support changing the Window.Page
mattleibow Jul 1, 2021
48f53cf
Merge remote-tracking branch 'origin/main' into dev/window-handler
mattleibow Jul 1, 2021
1bb9f9f
Disable some tests
mattleibow Jul 1, 2021
b73075d
IsApplicationOrWindowOrNull
mattleibow Jul 1, 2021
fc16fa2
Always fire this
mattleibow Jul 1, 2021
232c7d4
Merge remote-tracking branch 'origin/main' into dev/window-handler
mattleibow Jul 1, 2021
66c7857
nullable not needed
mattleibow Jul 1, 2021
5111da0
Make IWindowHandler internal for now
mattleibow Jul 1, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 21 additions & 14 deletions Microsoft.Maui-net6.sln
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,13 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Maui.Extensions",
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Maui.Controls.Sample.Profiling", "src\Controls\samples\Controls.Sample.Profiling\Maui.Controls.Sample.Profiling.csproj", "{75DB635C-0035-46E7-9A33-857D38082503}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{8F075D72-B023-4B5A-AB5E-43CA38B6CE92}"
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{D8CD878F-34BC-4393-881A-E3DD7348A13E}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Controls.Core.UnitTests-net6", "src\Controls\tests\Core.UnitTests\Controls.Core.UnitTests-net6.csproj", "{4FA0DFAE-1C4A-46BC-BC56-ABB12A0DAFBF}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Controls.Maps-net6", "src\Controls\Maps\src\Controls.Maps-net6.csproj", "{41CF73B5-D60E-4644-BA72-904CFF43C4AF}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Controls.Maps-net6", "src\Controls\Maps\src\Controls.Maps-net6.csproj", "{09D4CF7F-7B0D-45FE-B017-561B2A981912}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Controls.Core.UnitTests-net6", "src\Controls\tests\Core.UnitTests\Controls.Core.UnitTests-net6.csproj", "{DCA77B3F-73C2-488C-8D16-F5055DC3098C}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core.Benchmarks-net6", "src\Core\tests\Benchmarks\Core.Benchmarks-net6.csproj", "{A1B1052C-740D-4733-BB3F-8558B661E78D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -287,14 +289,18 @@ Global
{75DB635C-0035-46E7-9A33-857D38082503}.Release|Any CPU.ActiveCfg = Release|Any CPU
{75DB635C-0035-46E7-9A33-857D38082503}.Release|Any CPU.Build.0 = Release|Any CPU
{75DB635C-0035-46E7-9A33-857D38082503}.Release|Any CPU.Deploy.0 = Release|Any CPU
{4FA0DFAE-1C4A-46BC-BC56-ABB12A0DAFBF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4FA0DFAE-1C4A-46BC-BC56-ABB12A0DAFBF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4FA0DFAE-1C4A-46BC-BC56-ABB12A0DAFBF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4FA0DFAE-1C4A-46BC-BC56-ABB12A0DAFBF}.Release|Any CPU.Build.0 = Release|Any CPU
{09D4CF7F-7B0D-45FE-B017-561B2A981912}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{09D4CF7F-7B0D-45FE-B017-561B2A981912}.Debug|Any CPU.Build.0 = Debug|Any CPU
{09D4CF7F-7B0D-45FE-B017-561B2A981912}.Release|Any CPU.ActiveCfg = Release|Any CPU
{09D4CF7F-7B0D-45FE-B017-561B2A981912}.Release|Any CPU.Build.0 = Release|Any CPU
{41CF73B5-D60E-4644-BA72-904CFF43C4AF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{41CF73B5-D60E-4644-BA72-904CFF43C4AF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{41CF73B5-D60E-4644-BA72-904CFF43C4AF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{41CF73B5-D60E-4644-BA72-904CFF43C4AF}.Release|Any CPU.Build.0 = Release|Any CPU
{DCA77B3F-73C2-488C-8D16-F5055DC3098C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DCA77B3F-73C2-488C-8D16-F5055DC3098C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DCA77B3F-73C2-488C-8D16-F5055DC3098C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DCA77B3F-73C2-488C-8D16-F5055DC3098C}.Release|Any CPU.Build.0 = Release|Any CPU
{A1B1052C-740D-4733-BB3F-8558B661E78D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A1B1052C-740D-4733-BB3F-8558B661E78D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A1B1052C-740D-4733-BB3F-8558B661E78D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A1B1052C-740D-4733-BB3F-8558B661E78D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -345,9 +351,10 @@ Global
{081EE5E5-69D4-493C-9EB4-47423C4728AB} = {EC63FD88-5E12-46D7-B440-68F70241D987}
{6EDE0C1B-B718-4331-99BA-423042CDBE24} = {EC63FD88-5E12-46D7-B440-68F70241D987}
{75DB635C-0035-46E7-9A33-857D38082503} = {E1082E26-D700-4127-9329-66D673FD2D55}
{8F075D72-B023-4B5A-AB5E-43CA38B6CE92} = {459BF674-83CB-46F6-881F-A2D2117DBF4D}
{4FA0DFAE-1C4A-46BC-BC56-ABB12A0DAFBF} = {8F075D72-B023-4B5A-AB5E-43CA38B6CE92}
{09D4CF7F-7B0D-45FE-B017-561B2A981912} = {50C758FE-4E10-409A-94F5-A75480960864}
{D8CD878F-34BC-4393-881A-E3DD7348A13E} = {459BF674-83CB-46F6-881F-A2D2117DBF4D}
{41CF73B5-D60E-4644-BA72-904CFF43C4AF} = {50C758FE-4E10-409A-94F5-A75480960864}
{DCA77B3F-73C2-488C-8D16-F5055DC3098C} = {D8CD878F-34BC-4393-881A-E3DD7348A13E}
{A1B1052C-740D-4733-BB3F-8558B661E78D} = {C564DDD6-DE79-45CD-88EA-3F690481572A}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {0B8ABEAD-D2B5-4370-A187-62B5ABE4EE50}
Expand Down
2 changes: 1 addition & 1 deletion src/Compatibility/ControlGallery/src/Core/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class Startup : IStartup
{
internal static bool UseBlazor = false;

public void Configure(IAppHostBuilder appBuilder)
public virtual void Configure(IAppHostBuilder appBuilder)
{
appBuilder
.UseMauiApp<App>()
Expand Down
87 changes: 7 additions & 80 deletions src/Compatibility/ControlGallery/src/WinUI/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,89 +1,16 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Navigation;
using Windows.ApplicationModel;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.Foundation.Metadata;
using Windows.UI;
using Windows.UI.ViewManagement;

// The Blank Application template is documented at http://go.microsoft.com/fwlink/?LinkId=402347&clcid=0x409

namespace Microsoft.Maui.Controls.Compatibility.ControlGallery.WinUI
namespace Microsoft.Maui.Controls.Compatibility.ControlGallery.WinUI
{
public class MiddleApp : MauiWinUIApplication<Startup>
{
}

/// <summary>
/// Provides application-specific behavior to supplement the default Application class.
/// </summary>
sealed partial class App : MiddleApp
{
public static bool RunningAsUITests { get; private set; }
/// <summary>
/// Initializes the singleton application object. This is the first line of authored code
/// executed, and as such is the logical equivalent of main() or WinMain().
/// </summary>
public static bool RunningAsUITests { get; set; }

public App()
{
InitializeComponent();
//Suspending += OnSuspending;
}

public override MauiWinUIWindow CreateWindow()
{
return new MainPage();
}

/// <summary>
/// Invoked when the application is launched normally by the end user. Other entry points
/// will be used such as when the application is launched to open a specific file.
/// </summary>
/// <param name="e">Details about the launch request and process.</param>
protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs e)
{
base.OnLaunched(e);
if (!String.IsNullOrWhiteSpace(e.Arguments) &&
e.Arguments.Contains("RunningAsUITests"))
{
RunningAsUITests = true;
ControlGallery.App.PreloadTestCasesIssuesList = false;
}
}

/// <summary>
/// Invoked when Navigation to a certain page fails
/// </summary>
/// <param name="sender">The Frame which failed navigation</param>
/// <param name="e">Details about the navigation failure</param>
void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
{
throw new Exception("Failed to load Page " + e.SourcePageType.FullName);
}
}

/// <summary>
/// Invoked when application execution is being suspended. Application state is saved
/// without knowing whether the application will be terminated or resumed with the contents
/// of memory still intact.
/// </summary>
/// <param name="sender">The source of the suspend request.</param>
/// <param name="e">Details about the suspend request.</param>
void OnSuspending(object sender, SuspendingEventArgs e)
{
var deferral = e.SuspendingOperation.GetDeferral();
//TODO: Save application state and stop any background activity
deferral.Complete();
}
public class MiddleApp : MauiWinUIApplication<WinUIStartup>
{
}
}
}
11 changes: 0 additions & 11 deletions src/Compatibility/ControlGallery/src/WinUI/MainPage.xaml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,85 +1,79 @@
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409

using System;
using System;
using System.Globalization;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Controls.Compatibility.ControlGallery;
using Microsoft.Maui.Controls.Compatibility.ControlGallery.WinUI;
using Microsoft.Maui.Controls.Compatibility.Platform.UWP;
using Microsoft.Maui.Controls.Platform;
using Microsoft.Maui.Graphics;
using Microsoft.Maui.Hosting;
using Microsoft.Maui.LifecycleEvents;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media;
using Windows.Graphics.Display;
using Windows.System;
using Windows.UI.Core;
using Windows.UI.ViewManagement;

namespace Microsoft.Maui.Controls.Compatibility.ControlGallery.WinUI
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : MauiWinUIWindow
public class WinUIStartup : Startup
{
public MainPage()
public override void Configure(IAppHostBuilder appBuilder)
{
InitializeComponent();

// TODO WINUI3
// some tests need to window to be large enough to click on things
// can we make this only open to window size for UI Tests?
//var bounds = ApplicationView.GetForCurrentView().VisibleBounds;
//var scaleFactor = DisplayInformation.GetForCurrentView().RawPixelsPerViewPixel;
//var size = new Windows.Foundation.Size(bounds.Width * scaleFactor, bounds.Height * scaleFactor);
//ApplicationView.PreferredLaunchViewSize = size;
//ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.PreferredLaunchViewSize;

base.Configure(appBuilder);

appBuilder.ConfigureLifecycleEvents(lifecycle => lifecycle
.AddWindows(windows => windows
.OnLaunching((_, e) =>
{
if (!string.IsNullOrWhiteSpace(e.Arguments) && e.Arguments.Contains("RunningAsUITests"))
{
App.RunningAsUITests = true;
ControlGallery.App.PreloadTestCasesIssuesList = false;
}
})
.OnActivated(WinUIPageStartup.OnActivated)));
}
}

static class WinUIPageStartup
{
public static void OnActivated(UI.Xaml.Window window, UI.Xaml.WindowActivatedEventArgs e)
{
// When the native control gallery loads up, it'll let us know so we can add the nested native controls
MessagingCenter.Subscribe<NestedNativeControlGalleryPage>(this, NestedNativeControlGalleryPage.ReadyForNativeControlsMessage, AddNativeControls);
MessagingCenter.Subscribe<NestedNativeControlGalleryPage>(window, NestedNativeControlGalleryPage.ReadyForNativeControlsMessage, AddNativeControls);

// When the native binding gallery loads up, it'll let us know so we can set up the native bindings
MessagingCenter.Subscribe<NativeBindingGalleryPage>(this, NativeBindingGalleryPage.ReadyForNativeBindingsMessage, AddNativeBindings);
MessagingCenter.Subscribe<NativeBindingGalleryPage>(window, NativeBindingGalleryPage.ReadyForNativeBindingsMessage, AddNativeBindings);

this.Activated += MainPage_Activated;
}
Application.Current.PropertyChanged += OnAppPropertyChanged;

private void MainPage_Activated(object sender, UI.Xaml.WindowActivatedEventArgs args)
{
Application.Current.PropertyChanged += _app_PropertyChanged;
WireUpKeyDown();
WireUpKeyDown(window);

void OnAppPropertyChanged(object sender, global::System.ComponentModel.PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(Application.MainPage))
WireUpKeyDown(window);
}
}

// TODO WINUI3 not sure the best way to detect the content swap out
void WireUpKeyDown()
static void WireUpKeyDown(UI.Xaml.Window window)
{
this.DispatcherQueue.TryEnqueue(() =>
window.DispatcherQueue.TryEnqueue(() =>
{
if (this.Content != null)
if (window.Content != null)
{
this.Content.KeyDown -= OnKeyDown;
this.Content.KeyDown += OnKeyDown;
window.Content.KeyDown -= OnKeyDown;
window.Content.KeyDown += OnKeyDown;
}
else
{
WireUpKeyDown();
WireUpKeyDown(window);
}
});
}

private void _app_PropertyChanged(object sender, global::System.ComponentModel.PropertyChangedEventArgs e)
{
if (e.PropertyName == "MainPage")
{
WireUpKeyDown();
}
}

void OnKeyDown(object sender, KeyRoutedEventArgs args)
static void OnKeyDown(object sender, KeyRoutedEventArgs args)
{
if (args.Key == VirtualKey.Escape)
{
Expand All @@ -95,7 +89,7 @@ void OnKeyDown(object sender, KeyRoutedEventArgs args)
}
}

void AddNativeControls(NestedNativeControlGalleryPage page)
static void AddNativeControls(NestedNativeControlGalleryPage page)
{
if (page.NativeControlsAdded)
{
Expand All @@ -116,7 +110,7 @@ void AddNativeControls(NestedNativeControlGalleryPage page)
sl?.Children.Add(textBlock);

// Create and add a native Button
var button = new Microsoft.UI.Xaml.Controls.Button { Content = "Toggle Font Size", Height = 80 };
var button = new UI.Xaml.Controls.Button { Content = "Toggle Font Size", Height = 80 };
button.Click += (sender, args) => { textBlock.FontSize = textBlock.FontSize == 14 ? 24 : 14; };

sl?.Children.Add(button.ToView());
Expand All @@ -138,9 +132,7 @@ void AddNativeControls(NestedNativeControlGalleryPage page)
arrangeOverrideDelegate: (renderer, finalSize) =>
{
if (finalSize.Width <= 0 || double.IsInfinity(finalSize.Width))
{
return null;
}

FrameworkElement frameworkElement = renderer.Control;

Expand Down Expand Up @@ -168,7 +160,7 @@ void AddNativeControls(NestedNativeControlGalleryPage page)
page.NativeControlsAdded = true;
}

void AddNativeBindings(NativeBindingGalleryPage page)
static void AddNativeBindings(NativeBindingGalleryPage page)
{
if (page.NativeControlsAdded)
return;
Expand All @@ -187,10 +179,10 @@ void AddNativeBindings(NativeBindingGalleryPage page)
FontFamily = new FontFamily("HelveticaNeue")
};

var btnColor = new Microsoft.UI.Xaml.Controls.Button { Content = "Toggle Label Color", Height = 80 };
var btnColor = new UI.Xaml.Controls.Button { Content = "Toggle Label Color", Height = 80 };
btnColor.Click += (sender, args) => txbLabel.Foreground = SolidColorBrush.Pink.ToBrush();

var btnTextBox = new Microsoft.UI.Xaml.Controls.Button { Content = "Change text textbox", Height = 80 };
var btnTextBox = new UI.Xaml.Controls.Button { Content = "Change text textbox", Height = 80 };
btnTextBox.Click += (sender, args) => txbBox.Text = "Hello 2 way native";

txbLabel.SetBinding("Text", new Binding("NativeLabel"));
Expand All @@ -214,15 +206,15 @@ class ColorToBrushNativeBindingConverter : IValueConverter
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is Color)
return new Microsoft.UI.Xaml.Media.SolidColorBrush(ToWindowsColor((Color)value));
return new UI.Xaml.Media.SolidColorBrush(ToWindowsColor((Color)value));

return null;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is Microsoft.UI.Xaml.Media.SolidColorBrush)
return ToColor(((Microsoft.UI.Xaml.Media.SolidColorBrush)value).Color);
if (value is UI.Xaml.Media.SolidColorBrush)
return ToColor(((UI.Xaml.Media.SolidColorBrush)value).Color);

return null;
}
Expand All @@ -237,4 +229,4 @@ public static Color ToColor(Windows.UI.Color color)
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -344,16 +344,8 @@ protected override void OnElementChanged(ElementChangedEventArgs<NavigationPage>
_toolbarTracker.CollectionChanged += ToolbarTrackerOnCollectionChanged;
}

var parents = new List<Page>();
Page root = Element;
while (!Application.IsApplicationOrNull(root.RealParent))
{
root = (Page)root.RealParent;
parents.Add(root);
}

_toolbarTracker.Target = e.NewElement;
_toolbarTracker.AdditionalTargets = parents;
_toolbarTracker.AdditionalTargets = Element.GetParentPages();
UpdateMenu();

var navController = (INavigationPageController)e.NewElement;
Expand Down
Loading