示例#1
0
        protected Task CreateHandlerAndAddToWindow <THandler>(IElement view, Func <THandler, Task> action)
            where THandler : class, IElementHandler
        {
            return(InvokeOnMainThreadAsync(async() =>
            {
                IWindow window = null;

                if (view is IWindow w)
                {
                    window = w;
                }
                else if (view is Page page)
                {
                    window = new Controls.Window(page);
                }
                else
                {
                    window = new Controls.Window(new ContentPage()
                    {
                        Content = (View)view
                    });
                }

                await RunWindowTest <THandler>(window, (handler) => action(handler as THandler));
            }));
        }
示例#2
0
        public async Task SwappingOutAndroidContextDoesntCrash()
        {
            SetupBuilder();

            var shell = await CreateShellAsync(shell =>
            {
                shell.Items.Add(new FlyoutItem()
                {
                    Route = "FlyoutItem1", Items = { new ContentPage() }, Title = "Flyout Item"
                });
                shell.Items.Add(new FlyoutItem()
                {
                    Route = "FlyoutItem2", Items = { new ContentPage() }, Title = "Flyout Item"
                });
            });

            var window           = new Controls.Window(shell);
            var mauiContextStub1 = new ContextStub(MauiApp.Services);
            var activity         = mauiContextStub1.GetActivity();

            mauiContextStub1.Context = new ContextThemeWrapper(activity, Resource.Style.Maui_MainTheme_NoActionBar);

            await CreateHandlerAndAddToWindow <IWindowHandler>(window, async (handler) =>
            {
                await OnLoadedAsync(shell.CurrentPage);
                await OnNavigatedToAsync(shell.CurrentPage);
                await Task.Delay(100);
                await shell.GoToAsync("//FlyoutItem2");
            }, mauiContextStub1);

            var mauiContextStub2 = new ContextStub(MauiApp.Services);

            mauiContextStub2.Context = new ContextThemeWrapper(activity, Resource.Style.Maui_MainTheme_NoActionBar);

            await CreateHandlerAndAddToWindow <IWindowHandler>(window, async (handler) =>
            {
                await OnLoadedAsync(shell.CurrentPage);
                await OnNavigatedToAsync(shell.CurrentPage);
                await Task.Delay(100);
                await shell.GoToAsync("//FlyoutItem1");
                await shell.GoToAsync("//FlyoutItem2");
            }, mauiContextStub2);
        }
示例#3
0
文件: Window.cs 项目: zalid/elysium
 public static void SetCloseButtonToolTip([NotNull] Controls.Window obj, object value)
 {
     ValidationHelper.NotNull(obj, "obj");
     obj.SetValue(CloseButtonToolTipProperty, value);
 }
示例#4
0
文件: Window.cs 项目: zalid/elysium
 public static object GetRestoreButtonToolTip([NotNull] Controls.Window obj)
 {
     return(obj.GetValue(RestoreButtonToolTipProperty));
 }
示例#5
0
文件: Window.cs 项目: zalid/elysium
 public static void SetResizeBorderThickness([NotNull] Controls.Window obj, Thickness value)
 {
     ValidationHelper.NotNull(obj, "obj");
     obj.SetValue(ResizeBorderThicknessProperty, value);
 }
示例#6
0
文件: Window.cs 项目: zalid/elysium
 public static Thickness GetResizeBorderThickness([NotNull] Controls.Window obj)
 {
     ValidationHelper.NotNull(obj, "obj");
     ThicknessUtil.EnsureNonNegative();
     return(BoxingHelper <Thickness> .Unbox(obj.GetValue(ResizeBorderThicknessProperty)));
 }
示例#7
0
        protected Task CreateHandlerAndAddToWindow <THandler>(IElement view, Func <THandler, Task> action, IMauiContext mauiContext = null)
            where THandler : class, IElementHandler
        {
            mauiContext ??= MauiContext;

            return(InvokeOnMainThreadAsync(async() =>
            {
                IWindow window = null;

                var application = mauiContext.Services.GetService <IApplication>();

                if (view is IWindow w)
                {
                    window = w;
                }
                else if (view is Page page)
                {
                    window = new Controls.Window(page);
                }
                else
                {
                    window = new Controls.Window(new ContentPage()
                    {
                        Content = (View)view
                    });
                }

                if (application is ApplicationStub appStub)
                {
                    appStub.SetWindow((Window)window);

                    // Trigger the work flow of creating a window
                    _ = application.CreateWindow(null);
                }

                try
                {
                    await _takeOverMainContentSempahore.WaitAsync();

                    await SetupWindowForTests <THandler>(window, async() =>
                    {
                        IView content = window.Content;

                        if (content is IPageContainer <Page> pc)
                        {
                            content = pc.CurrentPage;
                            if (content == null)
                            {
                                // This is mainly a timing issue with Shell.
                                // Basically the `CurrentPage` on Shell isn't initialized until it's
                                // actually navigated to because it's a DataTemplate.
                                // The CurrentPage doesn't come into existence until the platform requests it.
                                // The initial `Navigated` events on Shell all fire a bit too early as well.
                                // Ideally I'd just use that instead of having to add a delay.
                                await Task.Delay(100);
                                content = pc.CurrentPage;
                            }

                            _ = content ?? throw new InvalidOperationException("Current Page Not Initialized");
                        }

                        await OnLoadedAsync(content as VisualElement);
#if WINDOWS
                        await Task.Delay(10);
#endif
                        if (typeof(THandler).IsAssignableFrom(window.Handler.GetType()))
                        {
                            await action((THandler)window.Handler);
                        }
                        else if (typeof(THandler).IsAssignableFrom(window.Content.Handler.GetType()))
                        {
                            await action((THandler)window.Content.Handler);
                        }
                        else if (window.Content is ContentPage cp && typeof(THandler).IsAssignableFrom(cp.Content.Handler.GetType()))
                        {
                            await action((THandler)cp.Content.Handler);
                        }
                        else
                        {
                            throw new Exception($"I can't work with {typeof(THandler)}");
                        }
                    }, mauiContext);
                }
示例#8
0
文件: Window.cs 项目: zalid/elysium
 public static object GetMaximizeButtonToolTip(Controls.Window obj)
 {
     return(obj.GetValue(MaximizeButtonToolTipProperty));
 }