Exemplo n.º 1
0
        protected virtual void ShowWindowViewController(
            NSViewController viewController,
            MvxWindowPresentationAttribute attribute,
            MvxViewModelRequest request)
        {
            var window = new NSWindow(
                new CGRect(attribute.PositionX, attribute.PositionY, attribute.Width, attribute.Height),
                attribute.WindowStyle,
                attribute.BufferingType,
                false,
                NSScreen.MainScreen)
            {
                Identifier = attribute.Identifier ?? viewController.GetType().Name
            };

            if (!string.IsNullOrEmpty(viewController.Title))
            {
                window.Title = viewController.Title;
            }

            Windows.Add(window);
            window.ContentView           = viewController.View;
            window.ContentViewController = viewController;

            var windowController = CreateWindowController(window);

            windowController.ShouldCascadeWindows = true;
            windowController.ShowWindow(null);
        }
Exemplo n.º 2
0
        private Task <bool> ShowWindow(Type viewType, MvxWindowPresentationAttribute attribute,
                                       MvxViewModelRequest request)
        {
            try
            {
                return(Task.Run(async() =>
                {
                    var requestText = GetRequestText(request);
                    var viewsContainer = Mvx.IoCProvider.Resolve <IMvxViewsContainer>();

                    await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.High,
                                                                                  async() =>
                    {
                        var appWindow = await AppWindow.TryCreateAsync();
                        var appWindowContentFrame = new Frame();
                        appWindowContentFrame.Navigate(viewType, requestText);
                        ElementCompositionPreview.SetAppWindowContent(appWindow, appWindowContentFrame);
                        await appWindow.TryShowAsync();
                        HandleBackButtonVisibility();
                    });
                    return true;
                }));
            }
            catch (Exception exception)
            {
                return(Task.FromResult(false));
            }
        }
Exemplo n.º 3
0
        protected virtual void UpdateWindow(MvxWindowPresentationAttribute attribute, NSWindow window)
        {
            var positionX = (float)window.Frame.X;
            var positionY = (float)window.Frame.Y;
            var width     = (float)window.Frame.Width;
            var height    = (float)window.Frame.Height;

            var newFrame = new CGRect(positionX, positionY, width, height);

            window.SetFrame(newFrame, false);

            window.StyleMask       = attribute.WindowStyle;
            window.BackingType     = attribute.BufferingType;
            window.TitleVisibility = attribute.TitleVisibility;
        }
Exemplo n.º 4
0
        protected virtual void UpdateWindow(MvxWindowPresentationAttribute attribute, NSWindow window)
        {
            var positionX = attribute.PositionX != MvxWindowPresentationAttribute.InitialPositionX ? attribute.PositionX : (float)window.Frame.X;
            var positionY = attribute.PositionY != MvxWindowPresentationAttribute.InitialPositionY ? attribute.PositionY : (float)window.Frame.Y;
            var width     = attribute.Width != MvxWindowPresentationAttribute.InitialWidth ? attribute.Width : (float)window.Frame.Width;
            var height    = attribute.Height != MvxWindowPresentationAttribute.InitialHeight ? attribute.Height : (float)window.Frame.Height;

            var newFrame = new CGRect(positionX, positionY, width, height);

            window.SetFrame(newFrame, false);

            window.StyleMask       = attribute.WindowStyle ?? window.StyleMask;
            window.BackingType     = attribute.BufferingType ?? window.BackingType;
            window.TitleVisibility = attribute.TitleVisibility ?? window.TitleVisibility;
        }
Exemplo n.º 5
0
        protected virtual Task <bool> ShowWindowViewController(
            NSViewController viewController,
            MvxWindowPresentationAttribute attribute,
            MvxViewModelRequest request)
        {
            NSWindow            window           = null;
            MvxWindowController windowController = null;

            if (!string.IsNullOrEmpty(attribute.WindowControllerName))
            {
                windowController = CreateWindowController(attribute);
                window           = windowController.Window;
            }

            if (window == null)
            {
                window = CreateWindow(attribute);

                if (windowController == null)
                {
                    windowController = CreateWindowController(window);
                    windowController.ShouldCascadeWindows = attribute.ShouldCascadeWindows;
                }
                windowController.Window = window;
            }
            else
            {
                UpdateWindow(attribute, window);
            }

            if (!Windows.Contains(window))
            {
                Windows.Add(window);
            }

            window.Identifier = attribute.Identifier ?? viewController.GetType().Name;

            if (!string.IsNullOrEmpty(viewController.Title))
            {
                window.Title = viewController.Title;
            }

            window.ContentView           = viewController.View;
            window.ContentViewController = viewController;
            windowController.ShowWindow(null);
            return(Task.FromResult(true));
        }
Exemplo n.º 6
0
        protected virtual MvxWindowController CreateWindowController(MvxWindowPresentationAttribute attribute)
        {
            MvxWindowController windowController;

            if (!string.IsNullOrEmpty(attribute.StoryboardName))
            {
                // Instantiate from storyboard
                var storyboard = NSStoryboard.FromName(attribute.StoryboardName, null);
                windowController = (MvxWindowController)storyboard.InstantiateControllerWithIdentifier(attribute.WindowControllerName);
            }
            else
            {
                // Instantiate using Reflection - failure is possible if blank constructor is missing
                windowController = (MvxWindowController)Activator.CreateInstance(Type.GetType(attribute.WindowControllerName));
            }
            windowController.ShouldCascadeWindows = attribute.ShouldCascadeWindows;
            return(windowController);
        }
Exemplo n.º 7
0
        protected virtual void ShowWindowViewController(
            NSViewController viewController,
            MvxWindowPresentationAttribute attribute,
            MvxViewModelRequest request)
        {
            NSWindow            window           = null;
            MvxWindowController windowController = null;

            if (!string.IsNullOrEmpty(attribute.WindowControllerName))
            {
                windowController = CreateWindowController(attribute);
                window           = windowController.Window;
            }

            if (window == null)
            {
                window = CreateWindow(attribute);

                if (windowController == null)
                {
                    windowController = CreateWindowController(window);
                    windowController.ShouldCascadeWindows = attribute.ShouldCascadeWindows ?? MvxWindowPresentationAttribute.DefaultShouldCascadeWindows;
                }
                windowController.Window = window;
            }
            else
            {
                UpdateWindow(attribute, window);
            }

            window.Identifier = attribute.Identifier ?? viewController.GetType().Name;

            if (!string.IsNullOrEmpty(viewController.Title))
            {
                window.Title = viewController.Title;
            }

            Windows.Add(window);
            window.ContentView           = viewController.View;
            window.ContentViewController = viewController;
            windowController.ShowWindow(null);

            _windowsToWindowControllers.Add(window, windowController);
        }
Exemplo n.º 8
0
        protected virtual NSWindow CreateWindow(MvxWindowPresentationAttribute attribute)
        {
            NSWindow window;
            var      positionX = attribute.PositionX;
            var      positionY = attribute.PositionY;
            var      width     = attribute.Width;
            var      height    = attribute.Height;

            window = new NSWindow(
                new CGRect(positionX, positionY, width, height),
                attribute.WindowStyle,
                attribute.BufferingType,
                false,
                NSScreen.MainScreen)
            {
                TitleVisibility = attribute.TitleVisibility,
            };
            return(window);
        }
Exemplo n.º 9
0
        protected virtual NSWindow CreateWindow(MvxWindowPresentationAttribute attribute)
        {
            NSWindow window;
            var      positionX = attribute.PositionX != MvxWindowPresentationAttribute.InitialPositionX ? attribute.PositionX : MvxWindowPresentationAttribute.DefaultPositionX;
            var      positionY = attribute.PositionY != MvxWindowPresentationAttribute.InitialPositionY ? attribute.PositionY : MvxWindowPresentationAttribute.DefaultPositionY;
            var      width     = attribute.Width != MvxWindowPresentationAttribute.InitialWidth ? attribute.Width : MvxWindowPresentationAttribute.DefaultWidth;
            var      height    = attribute.Height != MvxWindowPresentationAttribute.InitialHeight ? attribute.Height : MvxWindowPresentationAttribute.DefaultHeight;

            window = new NSWindow(
                new CGRect(positionX, positionY, width, height),
                attribute.WindowStyle ?? MvxWindowPresentationAttribute.DefaultWindowStyle,
                attribute.BufferingType ?? MvxWindowPresentationAttribute.DefaultBufferingType,
                false,
                NSScreen.MainScreen)
            {
                TitleVisibility = attribute.TitleVisibility ?? MvxWindowPresentationAttribute.DefaultTitleVisibility,
            };
            return(window);
        }
Exemplo n.º 10
0
        protected virtual Task <bool> ShowWindow(FrameworkElement element, MvxWindowPresentationAttribute attribute, MvxViewModelRequest request)
        {
            Window window;

            if (element is IMvxWindow mvxWindow)
            {
                window = (Window)element;
                mvxWindow.Identifier = attribute.Identifier ?? element.GetType().Name;
            }
            else if (element is Window normalWindow)
            {
                // Accept normal Window class
                window = normalWindow;
            }
            else
            {
                // Wrap in window
                window = new MvxWindow
                {
                    Identifier = attribute.Identifier ?? element.GetType().Name
                };
            }
            window.Closed += Window_Closed;
            FrameworkElementsDictionary.Add(window, new Stack <FrameworkElement>());

            if (!(element is Window))
            {
                FrameworkElementsDictionary[window].Push(element);
                window.Content = element;
            }

            if (attribute.Modal)
            {
                window.ShowDialog();
            }
            else
            {
                window.Show();
            }
            return(Task.FromResult(true));
        }
Exemplo n.º 11
0
        protected virtual void ShowWindow(FrameworkElement element, MvxWindowPresentationAttribute attribute, MvxViewModelRequest request)
        {
            Window window;

            if (element is MvxWindow)
            {
                window = (Window)element;
                ((MvxWindow)window).Identifier = attribute.Identifier ?? element.GetType().Name;
            }
            else if (element is Window)
            {
                // Accept normal Window class
                window = (Window)element;
            }
            else
            {
                // Wrap in window
                window = new MvxWindow
                {
                    Identifier = attribute.Identifier ?? element.GetType().Name
                };
            }
            window.Closed += Window_Closed;
            _frameworkElementsDictionary.Add(window, new Stack <FrameworkElement>());

            if (!(element is Window))
            {
                _frameworkElementsDictionary[window].Push(element);
                window.Content = element;
            }

            if (attribute.Modal)
            {
                window.ShowDialog();
            }
            else
            {
                window.Show();
            }
        }
Exemplo n.º 12
0
 private Task <bool> CloseWindow(IMvxViewModel viewModel, MvxWindowPresentationAttribute attribute)
 {
     return(base.ClosePage(viewModel, attribute));
 }