Esempio n. 1
0
        public async Task<ViewLifetimeControl> OpenAsync(Type page, object parameter = null, string title = null,
            ViewSizePreference size = ViewSizePreference.UseHalf)
        {
            WriteLine($"Page: {page}, Parameter: {parameter}, Title: {title}, Size: {size}");

            var currentView = ApplicationView.GetForCurrentView();
            title = title ?? currentView.Title;
           
            var newView = CoreApplication.CreateNewView();
            var dispatcher = new DispatcherWrapper(newView.Dispatcher);
            var newControl = await dispatcher.Dispatch(async () =>
            {                
                var control=ViewLifetimeControl.GetForCurrentView();
                var newWindow = Window.Current;
                var newAppView = ApplicationView.GetForCurrentView();
                newAppView.Title = title;                
                var nav = BootStrapper.Current.NavigationServiceFactory(BootStrapper.BackButton.Ignore, BootStrapper.ExistingContent.Exclude);
                control.NavigationService = nav;
                nav.Navigate(page, parameter);
                newWindow.Content = nav.Frame;
                newWindow.Activate();

                await ApplicationViewSwitcher
                    .TryShowAsStandaloneAsync(newAppView.Id, ViewSizePreference.Default, currentView.Id, size);
                return control;
            }).ConfigureAwait(false);
            return newControl;
        }
Esempio n. 2
0
        public async Task OpenAsync(
            Type page,
            object parameter        = null,
            string title            = null,
            ViewSizePreference size = ViewSizePreference.UseHalf)
        {
            var currentView = ApplicationView.GetForCurrentView();

            title = title ?? currentView.Title;

            var newView    = CoreApplication.CreateNewView();
            var dispatcher = new DispatcherUtility(newView.Dispatcher);
            await dispatcher.RunAsync(async() =>
            {
                var newWindow    = Window.Current;
                var newAppView   = ApplicationView.GetForCurrentView();
                newAppView.Title = title;

                var frame = BootStrapper.Current.NavigationServiceSetup(BootStrapper.BackButton.Ignore,
                                                                        BootStrapper.ExistingContent.Exclude,
                                                                        new Frame());
                frame.Navigate(page, parameter);
                newWindow.Content = frame.Frame;
                newWindow.Activate();

                await ApplicationViewSwitcher
                .TryShowAsStandaloneAsync(newAppView.Id, ViewSizePreference.Default, currentView.Id, size);
            });
        }
        public async Task <ViewLifetimeControl> OpenAsync(Type page, object parameter = null, string title = null,
                                                          ViewSizePreference size     = ViewSizePreference.UseHalf)
        {
            WriteLine($"Page: {page}, Parameter: {parameter}, Title: {title}, Size: {size}");

            var currentView = ApplicationView.GetForCurrentView();

            title = title ?? currentView.Title;

            var newView    = CoreApplication.CreateNewView();
            var dispatcher = new DispatcherWrapper(newView.Dispatcher);
            var newControl = await dispatcher.Dispatch(async() =>
            {
                var control               = ViewLifetimeControl.GetForCurrentView();
                var newWindow             = Window.Current;
                var newAppView            = ApplicationView.GetForCurrentView();
                newAppView.Title          = title;
                var nav                   = BootStrapper.Current.NavigationServiceFactory(BootStrapper.BackButton.Ignore, BootStrapper.ExistingContent.Exclude);
                control.NavigationService = nav;
                nav.Navigate(page, parameter);
                newWindow.Content = nav.Frame;
                newWindow.Activate();

                await ApplicationViewSwitcher
                .TryShowAsStandaloneAsync(newAppView.Id, ViewSizePreference.Default, currentView.Id, size);
                return(control);
            }).ConfigureAwait(false);

            return(newControl);
        }
Esempio n. 4
0
        public async Task <IViewLifetimeControl> OpenAsync(UIElement content, string title = null,
                                                           ViewSizePreference size         = ViewSizePreference.UseHalf)
        {
            this.Log($"Frame: {content}, Title: {title}, Size: {size}");

            var currentView = ApplicationView.GetForCurrentView();

            title = title ?? currentView.Title;

            var newView    = CoreApplication.CreateNewView();
            var dispatcher = DispatcherEx.Create(newView.Dispatcher);
            var newControl = await dispatcher.Dispatch(async() =>
            {
                var control      = ViewLifetimeControl.GetForCurrentView();
                var newWindow    = Window.Current;
                var newAppView   = ApplicationView.GetForCurrentView();
                newAppView.Title = title;

                // TODO: (Jerry)
                // control.NavigationService = nav;

                newWindow.Content = content;
                newWindow.Activate();

                await ApplicationViewSwitcher
                .TryShowAsStandaloneAsync(newAppView.Id, ViewSizePreference.Default, currentView.Id, size);
                return(control);
            }).ConfigureAwait(false);

            return(newControl);
        }
Esempio n. 5
0
        public async Task ShowAsync <T>(object param = null, ViewSizePreference size = ViewSizePreference.UseHalf)
        {
            if (this.IsOpen)
            {
                await CoreView.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () =>
                {
                    this.Close();
                });
            }
            else
            {
                this.Main = Window.Current;
            }

            this.CoreView = CoreApplication.CreateNewView();

            await CoreView.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () =>
            {
                this.Window             = Window.Current;
                var frame               = new Frame();
                frame.NavigationFailed += (s, e) => { System.Diagnostics.Debugger.Break(); };
                this.Window.Content     = frame;
                frame.Navigate(typeof(T), param);
                this.View = ApplicationView.GetForCurrentView();
                this.View.Consolidated += Helper_Consolidated;
            });

            if (await ApplicationViewSwitcher.TryShowAsStandaloneAsync(this.View.Id, size))
            {
                await ApplicationViewSwitcher.SwitchAsync(this.View.Id);
            }
        }
Esempio n. 6
0
 public Task OpenAsync(
     Type page,
     object parameter        = null,
     string title            = null,
     ViewSizePreference size = ViewSizePreference.UseHalf)
 {
     throw new NotImplementedException();
 }
Esempio n. 7
0
        // TODO: this will spawn a new window instead of navigating to an existing frame.
        public async Task <int> OpenAsync(Type page, string parameter = null, ViewSizePreference size = ViewSizePreference.UseHalf)
        {
            var             coreView = CoreApplication.CreateNewView();
            ApplicationView view     = null;
            var             create   = new Action(() =>
            {
                // setup content
                var frame = new Frame();
                frame.NavigationFailed += (s, e) => { System.Diagnostics.Debugger.Break(); };
                frame.Navigate(page, parameter);

                // create window
                var window     = Window.Current;
                window.Content = frame;

                // setup view/collapse
                view = ApplicationView.GetForCurrentView();
                Windows.Foundation.TypedEventHandler <ApplicationView, ApplicationViewConsolidatedEventArgs> consolidated = null;
                consolidated = new Windows.Foundation.TypedEventHandler <ApplicationView, ApplicationViewConsolidatedEventArgs>((s, e) =>
                {
                    (s as ApplicationView).Consolidated -= consolidated;
                    if (CoreApplication.GetCurrentView().IsMain)
                    {
                        return;
                    }
                    try { window.Close(); }
                    finally { CoreApplication.GetCurrentView().CoreWindow.Activate(); }
                });
                view.Consolidated += consolidated;
            });

            // execute create
            await WindowWrapper.Current().Dispatcher.DispatchAsync(create);

            // show view
            if (await ApplicationViewSwitcher.TryShowAsStandaloneAsync(view.Id, size))
            {
                // change focus
                await ApplicationViewSwitcher.SwitchAsync(view.Id);
            }
            return(view.Id);
        }
Esempio n. 8
0
        // TODO: this will spawn a new window instead of navigating to an existing frame.
        public async Task OpenAsync(Type page, object parameter = null, ViewSizePreference size = ViewSizePreference.UseHalf)
        {
            throw new NotImplementedException();

            //int id = default(int);
            //ApplicationView view = null;
            //var coreview = CoreApplication.CreateNewView();
            //var dispatcher = WindowWrapper.Current().Dispatcher;
            //await coreview.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            //{
            //    var nav = BootStrapper.Current.NavigationServiceFactory(false);
            //    Window.Current.Content = nav.Frame;
            //    nav.Navigate(page, parameter);

            //    view = ApplicationView.GetForCurrentView();
            //    view.Consolidated += (s, e) =>
            //    {
            //        if (!CoreApplication.GetCurrentView().IsMain)
            //            Window.Current.Close();
            //    };
            //    id = view.Id;
            //});
            //if (await ApplicationViewSwitcher.TryShowAsStandaloneAsync(id))
            //{
            //    // Switch to new view
            //    await ApplicationViewSwitcher.SwitchAsync(id);
            //}

            //var coreView = CoreApplication.CreateNewView();
            //ApplicationView view = null;
            //var create = new Action(() =>
            //{
            //    // setup content
            //    var frame = new Frame();
            //    frame.NavigationFailed += (s, e) => { System.Diagnostics.Debugger.Break(); };
            //    frame.Navigate(page, parameter);

            //    // create window
            //    var window = Window.Current;
            //    window.Content = frame;

            //    // setup view/collapse
            //    view = ApplicationView.GetForCurrentView();
            //    Windows.Foundation.TypedEventHandler<ApplicationView, ApplicationViewConsolidatedEventArgs> consolidated = null;
            //    consolidated = new Windows.Foundation.TypedEventHandler<ApplicationView, ApplicationViewConsolidatedEventArgs>((s, e) =>
            //    {
            //        (s as ApplicationView).Consolidated -= consolidated;
            //        if (CoreApplication.GetCurrentView().IsMain)
            //            return;
            //        try { window.Close(); }
            //        finally { CoreApplication.GetCurrentView().CoreWindow.Activate(); }
            //    });
            //    view.Consolidated += consolidated;
            //});

            //// execute create
            //await WindowWrapper.Current().Dispatcher.DispatchAsync(create);

            //// show view
            //if (await ApplicationViewSwitcher.TryShowAsStandaloneAsync(view.Id, size))
            //{
            //    // change focus
            //    await ApplicationViewSwitcher.SwitchAsync(view.Id);
            //}
            //return view.Id;
        }
        // TODO: this will spawn a new window instead of navigating to an existing frame.
        public async Task<int> OpenAsync(Type page, string parameter = null, ViewSizePreference size = ViewSizePreference.UseHalf)
        {
            var coreView = CoreApplication.CreateNewView();
            ApplicationView view = null;
            var create = new Action(() =>
            {
                // setup content
                var frame = new Frame();
                frame.NavigationFailed += (s, e) => { System.Diagnostics.Debugger.Break(); };
                frame.Navigate(page, parameter);

                // create window
                var window = Window.Current;
                window.Content = frame;

                // setup view/collapse
                view = ApplicationView.GetForCurrentView();
                Windows.Foundation.TypedEventHandler<ApplicationView, ApplicationViewConsolidatedEventArgs> consolidated = null;
                consolidated = new Windows.Foundation.TypedEventHandler<ApplicationView, ApplicationViewConsolidatedEventArgs>((s, e) =>
                {
                    (s as ApplicationView).Consolidated -= consolidated;
                    if (CoreApplication.GetCurrentView().IsMain)
                        return;
                    try { window.Close(); }
                    finally { CoreApplication.GetCurrentView().CoreWindow.Activate(); }
                });
                view.Consolidated += consolidated;
            });

            // execute create
            await WindowWrapper.Current().Dispatcher.DispatchAsync(create);

            // show view
            if (await ApplicationViewSwitcher.TryShowAsStandaloneAsync(view.Id, size))
            {
                // change focus
                await ApplicationViewSwitcher.SwitchAsync(view.Id);
            }
            return view.Id;
        }
Esempio n. 10
0
        /// <summary>
        /// Creates a new window.
        /// </summary>
        /// <param name="anchorViewId">The ID of the anchor window of the new window.</param>
        /// <param name="anchorWindowSizePreference">The preferred size for the anchor window.</param>
        /// <param name="newWindowSizePreference">The preferred size for the new window.</param>
        /// <returns>Returns a window creation result, which contains the a flag that determines whether the creation was successful and the navigation service, for the newly created window.</returns>
        private async Task <WindowCreationResult> CreateWindowAsync(Nullable <int> anchorViewId, ViewSizePreference anchorWindowSizePreference, ViewSizePreference newWindowSizePreference)
        {
            // Creates the result of the window creation a new navigation service for the window
            WindowCreationResult windowCreationResult = new WindowCreationResult();

            // Checks if this is the first creation of a new window (which is when there are no navigation services, yet), if so then the default window, which is created at application startup, is taken, otherwise a new window is created
            CoreApplicationView newWindow;

            if (this.navigationServices.Any())
            {
                newWindow = CoreApplication.CreateNewView();
            }
            else
            {
                newWindow = CoreApplication.GetCurrentView();
            }

            // Actually creates the new window and initializes it on its dispatcher
            await newWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                // Creates the navigation frame and the navigation service, which are needed to navigate within the newly created window
                Window.Current.Content = new Frame();
                windowCreationResult.NavigationService = new NavigationService(this.iocContainer, Window.Current, ApplicationView.GetForCurrentView(), Window.Current.Content as Frame);

                // Signs up for the closed event of the window, when the closed event is raised, then the life-cycle methods of the view model is called and the the window is disposed of
                Window.Current.Closed += async(sender, e) => await this.CloseWindowAsync(windowCreationResult.NavigationService);

                // Makes sure that the window is properly activated
                Window.Current.Activate();
            });

            // Shows the window and determines whether the creation was successful (but the window only needs to shown, if this is not the first navigation, because the default window, that is created at application startup, is already open)
            if (this.navigationServices.Any())
            {
                if (anchorViewId.HasValue)
                {
                    windowCreationResult.WasSuccessful = await ApplicationViewSwitcher.TryShowAsStandaloneAsync(windowCreationResult.NavigationService.ApplicationView.Id, newWindowSizePreference, anchorViewId.Value, anchorWindowSizePreference);
                }
                else
                {
                    windowCreationResult.WasSuccessful = await ApplicationViewSwitcher.TryShowAsStandaloneAsync(windowCreationResult.NavigationService.ApplicationView.Id, newWindowSizePreference);
                }
            }
            else
            {
                windowCreationResult.WasSuccessful = true;
            }

            // Returns the result
            return(windowCreationResult);
        }
Esempio n. 11
0
 public Task ShowAsync <T>(object param = null, ViewSizePreference size = ViewSizePreference.UseHalf)
 {
     return(_helper.ShowAsync <T>(param, size));
 }
Esempio n. 12
0
        // TODO: this will spawn a new window instead of navigating to an existing frame.
        public async Task OpenAsync(Type page, object parameter = null, ViewSizePreference size = ViewSizePreference.UseHalf)
        {
            throw new NotImplementedException();

            //int id = default(int);
            //ApplicationView view = null;
            //var coreview = CoreApplication.CreateNewView();
            //var dispatcher = WindowWrapper.Current().Dispatcher;
            //await coreview.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            //{
            //    var nav = BootStrapper.Current.NavigationServiceFactory(false);
            //    Window.Current.Content = nav.Frame;
            //    nav.Navigate(page, parameter);

            //    view = ApplicationView.GetForCurrentView();
            //    view.Consolidated += (s, e) =>
            //    {
            //        if (!CoreApplication.GetCurrentView().IsMain)
            //            Window.Current.Close();
            //    };
            //    id = view.Id;
            //});
            //if (await ApplicationViewSwitcher.TryShowAsStandaloneAsync(id))
            //{
            //    // Switch to new view
            //    await ApplicationViewSwitcher.SwitchAsync(id);
            //}

            //var coreView = CoreApplication.CreateNewView();
            //ApplicationView view = null;
            //var create = new Action(() =>
            //{
            //    // setup content
            //    var frame = new Frame();
            //    frame.NavigationFailed += (s, e) => { System.Diagnostics.Debugger.Break(); };
            //    frame.Navigate(page, parameter);

            //    // create window
            //    var window = Window.Current;
            //    window.Content = frame;

            //    // setup view/collapse
            //    view = ApplicationView.GetForCurrentView();
            //    Windows.Foundation.TypedEventHandler<ApplicationView, ApplicationViewConsolidatedEventArgs> consolidated = null;
            //    consolidated = new Windows.Foundation.TypedEventHandler<ApplicationView, ApplicationViewConsolidatedEventArgs>((s, e) =>
            //    {
            //        (s as ApplicationView).Consolidated -= consolidated;
            //        if (CoreApplication.GetCurrentView().IsMain)
            //            return;
            //        try { window.Close(); }
            //        finally { CoreApplication.GetCurrentView().CoreWindow.Activate(); }
            //    });
            //    view.Consolidated += consolidated;
            //});

            //// execute create
            //await WindowWrapper.Current().Dispatcher.DispatchAsync(create);

            //// show view
            //if (await ApplicationViewSwitcher.TryShowAsStandaloneAsync(view.Id, size))
            //{
            //    // change focus
            //    await ApplicationViewSwitcher.SwitchAsync(view.Id);
            //}
            //return view.Id;
        }
Esempio n. 13
0
        public Task <ViewLifetimeControl> OpenAsync(Type page, object parameter = null, string title = null, ViewSizePreference size = ViewSizePreference.UseHalf)
        {
            DebugWrite($"Page: {page}, Parameter: {parameter}, Title: {title}, Size: {size}");

            return(ViewService.OpenAsync(page, parameter, title, size));
        }
Esempio n. 14
0
        public async Task OpenAsync(Type page, object parameter = null, string title = null, ViewSizePreference size = ViewSizePreference.UseHalf)
        {
            var currentView = ApplicationView.GetForCurrentView();
            title = title ?? currentView.Title;

            var newView = CoreApplication.CreateNewView();
            var dispatcher = new DispatcherWrapper(newView.Dispatcher);
            await dispatcher.DispatchAsync(async () =>
            {
                var newWindow = Window.Current;
                var newAppView = ApplicationView.GetForCurrentView();
                newAppView.Title = title;

                var frame = BootStrapper.Current.NavigationServiceFactory(BootStrapper.BackButton.Ignore, BootStrapper.ExistingContent.Exclude);
                frame.Navigate(page, parameter);
                newWindow.Content = frame.Frame;
                newWindow.Activate();

                await ApplicationViewSwitcher
                    .TryShowAsStandaloneAsync(newAppView.Id, ViewSizePreference.Default, currentView.Id, size);
            });
        }
Esempio n. 15
0
        public async Task <ViewLifetimeControl> OpenAsync(Type page, object parameter = null, string title = null,
                                                          ViewSizePreference size     = ViewSizePreference.UseHalf, int session = 0, string id = "0")
        {
            WriteLine($"Page: {page}, Parameter: {parameter}, Title: {title}, Size: {size}");

            var currentView = ApplicationView.GetForCurrentView();

            title = title ?? currentView.Title;



            if (parameter != null && _windows.TryGetValue(parameter, out DispatcherWrapper value))
            {
                var newControl = await value.Dispatch(async() =>
                {
                    var control    = ViewLifetimeControl.GetForCurrentView();
                    var newAppView = ApplicationView.GetForCurrentView();

                    var preferences        = ViewModePreferences.CreateDefault(ApplicationViewMode.Default);
                    preferences.CustomSize = new Windows.Foundation.Size(360, 640);

                    await ApplicationViewSwitcher
                    .SwitchAsync(newAppView.Id, currentView.Id, ApplicationViewSwitchingOptions.Default);

                    return(control);
                }).ConfigureAwait(false);

                return(newControl);
            }
            else
            {
                var newView    = CoreApplication.CreateNewView();
                var dispatcher = new DispatcherWrapper(newView.Dispatcher);

                if (parameter != null)
                {
                    _windows[parameter] = dispatcher;
                }

                var bounds = Window.Current.Bounds;

                var newControl = await dispatcher.Dispatch(async() =>
                {
                    var newWindow    = Window.Current;
                    var newAppView   = ApplicationView.GetForCurrentView();
                    newAppView.Title = title;

                    var control       = ViewLifetimeControl.GetForCurrentView();
                    control.Released += (s, args) =>
                    {
                        if (parameter != null)
                        {
                            _windows.TryRemove(parameter, out DispatcherWrapper ciccio);
                        }

                        newWindow.Close();
                    };

                    var nav = BootStrapper.Current.NavigationServiceFactory(BootStrapper.BackButton.Ignore, BootStrapper.ExistingContent.Exclude, session, id, false);
                    control.NavigationService = nav;
                    nav.Navigate(page, parameter);
                    newWindow.Content = BootStrapper.Current.CreateRootElement(nav);
                    newWindow.Activate();

                    await ApplicationViewSwitcher
                    .TryShowAsStandaloneAsync(newAppView.Id, ViewSizePreference.Default, currentView.Id, size);
                    //newAppView.TryResizeView(new Windows.Foundation.Size(360, bounds.Height));
                    newAppView.TryResizeView(new Windows.Foundation.Size(360, 640));

                    return(control);
                }).ConfigureAwait(false);

                return(newControl);
            }
        }
Esempio n. 16
0
 /// <summary>
 /// Creates a new window and navigates to the specified view.
 /// </summary>
 /// <typeparam name="TView">The type of the view to which the user should be navigated in the new window.</typeparam>
 /// <param name="parameters">The parameters, which are injected in to the view model of the view.</param>
 /// <param name="newWindowSizePreference">The size preference for the new window, which determines how the new window is arranged in respect to the anchor window.</param>
 /// <param name="anchorWindowNavigationService">The navigation service of the window, which is the anchor for the new window. This can be used to specify how the two windows are being arranged by Windows.</param>
 /// <returns>Returns the result of the navigation.</returns>
 public Task <WindowNavigationResult> NavigateAsync <TView>(object parameters, ViewSizePreference newWindowSizePreference, NavigationService anchorWindowNavigationService) where TView : Page => this.NavigateAsync <TView>(parameters, newWindowSizePreference, anchorWindowNavigationService, ViewSizePreference.Default);
Esempio n. 17
0
 /// <summary>
 /// Creates a new window and navigates to the specified view.
 /// </summary>
 /// <typeparam name="TView">The type of the view to which the user should be navigated in the new window.</typeparam>
 /// <param name="newWindowSizePreference">The size preference for the new window, which determines how the new window is arranged in respect to the window from which the new window is being opened.</param>
 /// <returns>Returns the result of the navigation.</returns>
 public Task <WindowNavigationResult> NavigateAsync <TView>(ViewSizePreference newWindowSizePreference) where TView : Page => this.NavigateAsync <TView>(null, newWindowSizePreference, null, ViewSizePreference.Default);
Esempio n. 18
0
        public async Task OpenAsync(Type page, object parameter = null, string title = null, ViewSizePreference size = ViewSizePreference.UseHalf)
        {
            DebugWrite($"Page: {page}, Parameter: {parameter}, Title: {title}, Size: {size}");

            var currentView = ApplicationView.GetForCurrentView();

            title = title ?? currentView.Title;

            var newView    = CoreApplication.CreateNewView();
            var dispatcher = new DispatcherWrapper(newView.Dispatcher);
            await dispatcher.DispatchAsync(async() =>
            {
                var newWindow    = this.GetWindowWrapper().Window;
                var newAppView   = ApplicationView.GetForCurrentView();
                newAppView.Title = title;

                var nav = BootStrapper.Current.NavigationServiceFactory(BootStrapper.BackButton.Ignore, BootStrapper.ExistingContent.Exclude);
                nav.Navigate(page, parameter);
                newWindow.Content = nav.Frame;
                newWindow.Activate();

                await ApplicationViewSwitcher
                .TryShowAsStandaloneAsync(newAppView.Id, ViewSizePreference.Default, currentView.Id, size);
            });
        }
Esempio n. 19
0
        /// <summary>
        /// Creates a new window and navigates to the specified view.
        /// </summary>
        /// <typeparam name="TView">The type of the view to which the user should be navigated in the new window.</typeparam>
        /// <param name="parameters">The parameters, which are injected in to the view model of the view.</param>
        /// <param name="newWindowSizePreference">The size preference for the new window, which determines how the new window is arranged in respect to the anchor window.</param>
        /// <param name="anchorWindowNavigationService">The navigation service of the window, which is the anchor for the new window. This can be used to specify how the two windows are being arranged by Windows.</param>
        /// <param name="anchorWindowSizePreference">The size preference for the anchor window, which determines how the anchor window is arranged in respect to the new window.</param>
        /// <returns>Returns the result of the navigation.</returns>
        public async Task <WindowNavigationResult> NavigateAsync <TView>(object parameters, ViewSizePreference newWindowSizePreference, NavigationService anchorWindowNavigationService, ViewSizePreference anchorWindowSizePreference) where TView : Page
        {
            // Creates the new window
            WindowCreationResult result = await this.CreateWindowAsync(anchorWindowNavigationService?.ApplicationView.Id, anchorWindowSizePreference, newWindowSizePreference);

            // Checks if the window could be created, if not then the navigation can not be performed
            if (!result.WasSuccessful)
            {
                return new WindowNavigationResult {
                           Result = NavigationResult.Canceled
                }
            }
            ;

            // Navigates to the specified view
            if (await result.NavigationService.NavigateAsync <TView>(parameters) == NavigationResult.Canceled)
            {
                // Since the view could not be navigated to, the new window is closed, and the navigation is aborted
                await result.NavigationService.CloseWindowAsync(false, NavigationReason.WindowClosed);

                return(new WindowNavigationResult {
                    Result = NavigationResult.Canceled
                });
            }

            // Adds the new navigation service to the list of navigation services and invokes the window created event
            this.navigationServices.Add(result.NavigationService);
            this.WindowCreated?.Invoke(this, new WindowEventArgs(result.NavigationService));

            // Since the navigation was successful, the navigation service is returned
            return(new WindowNavigationResult
            {
                Result = NavigationResult.Navigated,
                NavigationService = result.NavigationService
            });
        }
Esempio n. 20
0
        public Task <IViewLifetimeControl> OpenAsync(Type page, object parameter = null, string title = null, ViewSizePreference size = ViewSizePreference.UseHalf)
        {
            this.Log($"Page: {page}, Parameter: {parameter}, Title: {title}, Size: {size}");

            var frame = new Frame();
            var nav   = new NavigationService(frame);

            nav.Navigate(page, parameter);

            return(ViewService.OpenAsync(frame, title, size));
        }
Esempio n. 21
0
        public async Task <ViewLifetimeControl> OpenAsync(Type page, object parameter = null, string title = null,
                                                          ViewSizePreference size     = ViewSizePreference.UseHalf, int session = 0, string id = "0")
        {
            Logger.Info($"Page: {page}, Parameter: {parameter}, Title: {title}, Size: {size}");

            var currentView = ApplicationView.GetForCurrentView();

            title ??= currentView.Title;



            if (parameter != null && _windows.TryGetValue(parameter, out IDispatcherContext value))
            {
                var newControl = await value.DispatchAsync(async() =>
                {
                    var control    = ViewLifetimeControl.GetForCurrentView();
                    var newAppView = ApplicationView.GetForCurrentView();

                    await ApplicationViewSwitcher
                    .SwitchAsync(newAppView.Id, currentView.Id, ApplicationViewSwitchingOptions.Default);

                    return(control);
                }).ConfigureAwait(false);

                return(newControl);
            }
            else
            {
                //if (ApiInformation.IsPropertyPresent("Windows.UI.ViewManagement.ApplicationView", "PersistedStateId"))
                //{
                //    try
                //    {
                //        ApplicationView.ClearPersistedState("Calls");
                //    }
                //    catch { }
                //}

                var newView    = CoreApplication.CreateNewView();
                var dispatcher = new DispatcherContext(newView.DispatcherQueue);

                if (parameter != null)
                {
                    _windows[parameter] = dispatcher;
                }

                var bounds = Window.Current.Bounds;

                var newControl = await dispatcher.DispatchAsync(async() =>
                {
                    var newWindow    = Window.Current;
                    var newAppView   = ApplicationView.GetForCurrentView();
                    newAppView.Title = title;

                    if (ApiInformation.IsPropertyPresent("Windows.UI.ViewManagement.ApplicationView", "PersistedStateId"))
                    {
                        newAppView.PersistedStateId = "Floating";
                    }

                    var control       = ViewLifetimeControl.GetForCurrentView();
                    control.Released += (s, args) =>
                    {
                        if (parameter != null)
                        {
                            _windows.TryRemove(parameter, out IDispatcherContext _);
                        }

                        //newWindow.Close();
                    };

                    var nav = BootStrapper.Current.NavigationServiceFactory(BootStrapper.BackButton.Ignore, BootStrapper.ExistingContent.Exclude, session, id, false);
                    nav.Navigate(page, parameter);
                    newWindow.Content = BootStrapper.Current.CreateRootElement(nav);
                    newWindow.Activate();

                    await ApplicationViewSwitcher
                    .TryShowAsStandaloneAsync(newAppView.Id, ViewSizePreference.Default, currentView.Id, size);
                    //newAppView.TryResizeView(new Windows.Foundation.Size(360, bounds.Height));
                    newAppView.TryResizeView(new Size(360, 640));

                    return(control);
                }).ConfigureAwait(false);

                return(newControl);
            }
        }