diff --git a/src/Compatibility/ControlGallery/src/WinUI/App.xaml b/src/Compatibility/ControlGallery/src/WinUI/App.xaml index 71ea354b880d..9bef4326848a 100644 --- a/src/Compatibility/ControlGallery/src/WinUI/App.xaml +++ b/src/Compatibility/ControlGallery/src/WinUI/App.xaml @@ -1,4 +1,5 @@ - - - - - + + + + + - + diff --git a/src/Compatibility/ControlGallery/src/WinUI/App.xaml.cs b/src/Compatibility/ControlGallery/src/WinUI/App.xaml.cs index 98b3f2f1fb58..4512356fa916 100644 --- a/src/Compatibility/ControlGallery/src/WinUI/App.xaml.cs +++ b/src/Compatibility/ControlGallery/src/WinUI/App.xaml.cs @@ -21,12 +21,15 @@ namespace Microsoft.Maui.Controls.Compatibility.ControlGallery.WinUI { + public class MiddleApp : MauiWinUIApplication + { + } + /// /// Provides application-specific behavior to supplement the default Application class. /// - sealed partial class App : Microsoft.UI.Xaml.Application + sealed partial class App : MiddleApp { - private UI.Xaml.Window m_window; public static bool RunningAsUITests { get; private set; } /// /// Initializes the singleton application object. This is the first line of authored code @@ -38,6 +41,11 @@ public App() //Suspending += OnSuspending; } + public override MauiWinUIWindow CreateWindow() + { + return new MainPage(); + } + /// /// 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. @@ -45,15 +53,13 @@ public App() /// Details about the launch request and process. 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; } - - m_window = new MainPage(); - Maui.Controls.Compatibility.Forms.Init(m_window as MainPage); } /// diff --git a/src/Compatibility/ControlGallery/src/WinUI/MainPage.xaml b/src/Compatibility/ControlGallery/src/WinUI/MainPage.xaml index 9596c8b2b670..4eeb4f561e84 100644 --- a/src/Compatibility/ControlGallery/src/WinUI/MainPage.xaml +++ b/src/Compatibility/ControlGallery/src/WinUI/MainPage.xaml @@ -1,4 +1,5 @@ - - \ No newline at end of file + \ No newline at end of file diff --git a/src/Compatibility/ControlGallery/src/WinUI/MainPage.xaml.cs b/src/Compatibility/ControlGallery/src/WinUI/MainPage.xaml.cs index 44566d44233c..7f3e58876e9c 100644 --- a/src/Compatibility/ControlGallery/src/WinUI/MainPage.xaml.cs +++ b/src/Compatibility/ControlGallery/src/WinUI/MainPage.xaml.cs @@ -22,10 +22,8 @@ namespace Microsoft.Maui.Controls.Compatibility.ControlGallery.WinUI /// /// An empty page that can be used on its own or navigated to within a Frame. /// - public sealed partial class MainPage + public sealed partial class MainPage : MauiWinUIWindow { - ControlGallery.App _app; - public MainPage() { InitializeComponent(); @@ -47,19 +45,12 @@ public MainPage() // When the native binding gallery loads up, it'll let us know so we can set up the native bindings MessagingCenter.Subscribe(this, NativeBindingGalleryPage.ReadyForNativeBindingsMessage, AddNativeBindings); + this.Activated += MainPage_Activated; } - public override Application CreateApplication() - { - _app = new ControlGallery.App(); - return _app; - } - - public override void LoadApplication(Application application) + private void MainPage_Activated(object sender, UI.Xaml.WindowActivatedEventArgs args) { - base.LoadApplication(application); - - _app.PropertyChanged += _app_PropertyChanged; + Application.Current.PropertyChanged += _app_PropertyChanged; WireUpKeyDown(); } @@ -92,12 +83,15 @@ void OnKeyDown(object sender, KeyRoutedEventArgs args) { if (args.Key == VirtualKey.Escape) { - _app.Reset(); + (Application.Current as ControlGallery.App) + .Reset(); + args.Handled = true; } else if (args.Key == VirtualKey.F1) { - _app.PlatformTest(); + (Application.Current as ControlGallery.App) + .PlatformTest(); } } diff --git a/src/Compatibility/Core/src/Android/AppCompat/FormsAppCompatActivity.cs b/src/Compatibility/Core/src/Android/AppCompat/FormsAppCompatActivity.cs index d034d2a39515..9bd6ce5ff0a5 100644 --- a/src/Compatibility/Core/src/Android/AppCompat/FormsAppCompatActivity.cs +++ b/src/Compatibility/Core/src/Android/AppCompat/FormsAppCompatActivity.cs @@ -203,14 +203,14 @@ void OnCreate( Profile.FramePartition("SetSupportActionBar"); AToolbar bar = null; - if (ToolbarResource == 0) + if (_toolbarResource == 0) { ToolbarResource = Resource.Layout.toolbar; } - if (TabLayoutResource == 0) + if (_tabLayoutResource == 0) { - TabLayoutResource = Resource.Layout.tabbar; + _tabLayoutResource = Resource.Layout.tabbar; } if (ToolbarResource != 0) @@ -504,9 +504,31 @@ internal class DefaultApplication : Application public static event BackButtonPressedEventHandler BackPressed; - public static int TabLayoutResource { get; set; } + static int _tabLayoutResource; + public static int TabLayoutResource + { + get + { + if (_tabLayoutResource == 0) + return Resource.Layout.tabbar; + + return _tabLayoutResource; + } + set => _tabLayoutResource = value; + } - public static int ToolbarResource { get; set; } + static int _toolbarResource; + public static int ToolbarResource + { + get + { + if (_toolbarResource == 0) + return Resource.Layout.toolbar; + + return _toolbarResource; + } + set => _toolbarResource = value; + } #endregion } diff --git a/src/Compatibility/Core/src/Android/AppCompat/NavigationPageRenderer.cs b/src/Compatibility/Core/src/Android/AppCompat/NavigationPageRenderer.cs index bbd11c0e711d..dcb0923242a3 100644 --- a/src/Compatibility/Core/src/Android/AppCompat/NavigationPageRenderer.cs +++ b/src/Compatibility/Core/src/Android/AppCompat/NavigationPageRenderer.cs @@ -958,8 +958,7 @@ void UpdateToolbar() toggle.SyncState(); } - var activity = (AppCompatActivity)context.GetActivity(); - var icon = new DrawerArrowDrawable(activity.SupportActionBar.ThemedContext); + var icon = new DrawerArrowDrawable(context.GetThemedContext()); icon.Progress = 1; bar.NavigationIcon = icon; diff --git a/src/Compatibility/Core/src/WinUI/Resources.xaml b/src/Compatibility/Core/src/WinUI/Resources.xaml index 075e976de3b4..d2f514c9f0ca 100644 --- a/src/Compatibility/Core/src/WinUI/Resources.xaml +++ b/src/Compatibility/Core/src/WinUI/Resources.xaml @@ -49,7 +49,7 @@ - diff --git a/src/Compatibility/Core/src/iOS/Renderers/NavigationRenderer.cs b/src/Compatibility/Core/src/iOS/Renderers/NavigationRenderer.cs index 19c00188b7ea..abc9d5dd0d3d 100644 --- a/src/Compatibility/Core/src/iOS/Renderers/NavigationRenderer.cs +++ b/src/Compatibility/Core/src/iOS/Renderers/NavigationRenderer.cs @@ -1472,10 +1472,10 @@ public override async void DidMoveToParentViewController(UIViewController parent public override UIViewController ChildViewControllerForStatusBarHidden() { - return (UIViewController)Platform.GetRenderer(Current); + return Platform.GetRenderer(Current).ViewController; } - public override UIViewController ChildViewControllerForHomeIndicatorAutoHidden => (UIViewController)Platform.GetRenderer(Current); + public override UIViewController ChildViewControllerForHomeIndicatorAutoHidden => Platform.GetRenderer(Current).ViewController; void IEffectControlProvider.RegisterEffect(Effect effect) { diff --git a/src/Controls/src/Core/AppHostBuilderExtensions.cs b/src/Controls/src/Core/AppHostBuilderExtensions.cs index 83915a2a011f..2ab41441e5e1 100644 --- a/src/Controls/src/Core/AppHostBuilderExtensions.cs +++ b/src/Controls/src/Core/AppHostBuilderExtensions.cs @@ -12,7 +12,6 @@ public static class AppHostBuilderExtensions { static readonly Dictionary DefaultMauiControlHandlers = new Dictionary { - { typeof(NavigationPage), typeof(NavigationPageHandler) }, #if WINDOWS { typeof(Shell), typeof(ShellHandler) }, #endif diff --git a/src/Core/src/Platform/Windows/MauiWinUIApplication.cs b/src/Core/src/Platform/Windows/MauiWinUIApplication.cs index 76fb95321f38..a3f784870127 100644 --- a/src/Core/src/Platform/Windows/MauiWinUIApplication.cs +++ b/src/Core/src/Platform/Windows/MauiWinUIApplication.cs @@ -13,6 +13,9 @@ namespace Microsoft.Maui public class MauiWinUIApplication : MauiWinUIApplication where TStartup : IStartup, new() { + public virtual UI.Xaml.Window CreateWindow() => + new MauiWinUIWindow(); + protected override void OnLaunched(UI.Xaml.LaunchActivatedEventArgs args) { LaunchActivatedEventArgs = args; diff --git a/src/Core/src/Platform/Windows/Styles/Resources.xaml b/src/Core/src/Platform/Windows/Styles/Resources.xaml index 71c4339835af..b3bb2b40bc49 100644 --- a/src/Core/src/Platform/Windows/Styles/Resources.xaml +++ b/src/Core/src/Platform/Windows/Styles/Resources.xaml @@ -18,5 +18,9 @@ true + +