Beispiel #1
0
        public override SynchronizationContext CreateCopy()
        {
            var copyControl = ViewLifetimeControl.GetForCurrentView();

            copyControl = copyControl != control ? copyControl : control;
            return(new SecondaryViewSynchronizationContextDecorator(copyControl, context.CreateCopy()));
        }
Beispiel #2
0
 public SecondaryViewSynchronizationContextDecorator(ViewLifetimeControl control, SynchronizationContext context)
 {
     if (context == null)
     {
         throw new ArgumentNullException(nameof(context));
     }
     if (control == null)
     {
         throw new ArgumentNullException(nameof(control));
     }
     this.control = control;
     this.context = context;
 }
Beispiel #3
0
        internal static void OnWindowCreated()
        {
            var view = CoreApplication.GetCurrentView();

            if (!view.IsMain && !view.IsHosted)
            {
                var control = ViewLifetimeControl.GetForCurrentView();
                //This one time it should be made manually, as after Consolidate event fires the inner reference number should become zero
                control.StartViewInUse();
                //This is necessary to not make control.StartViewInUse()/control.StopViewInUse() manually on each and every async call. Facade will do it for you
                SynchronizationContext.SetSynchronizationContext(new SecondaryViewSynchronizationContextDecorator(control,
                                                                                                                  SynchronizationContext.Current));
            }
        }
Beispiel #4
0
        public async Task <ViewLifetimeControl> OpenAsync(ViewServiceParams parameters)
        {
            //if (ApiInformation.IsPropertyPresent("Windows.UI.ViewManagement.ApplicationView", "PersistedStateId"))
            //{
            //    try
            //    {
            //        ApplicationView.ClearPersistedState("Calls");
            //    }
            //    catch { }
            //}

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

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

                newAppView.Title = parameters.Title ?? string.Empty;

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

                var control       = ViewLifetimeControl.GetForCurrentView();
                control.Released += (s, args) =>
                {
                    newWindow.Close();
                };

                newWindow.Content = parameters.Content(control);
                newWindow.Activate();

                var preferences        = ViewModePreferences.CreateDefault(parameters.ViewMode);
                preferences.CustomSize = new Size(parameters.Width, parameters.Height);

                await ApplicationViewSwitcher.TryShowAsViewModeAsync(newAppView.Id, parameters.ViewMode, preferences);
                //newAppView.TryResizeView(new Size(parameters.Width, parameters.Height));

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

            return(newControl);
        }
Beispiel #5
0
        public async Task <ViewLifetimeControl> OpenAsync(Func <UIElement> content, object parameter, double width, double height)
        {
            if (_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.CompactOverlay);
                    preferences.CustomSize = new Size(width, height);

                    await ApplicationViewSwitcher
                    .TryShowAsViewModeAsync(newAppView.Id, ApplicationViewMode.CompactOverlay, preferences);

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

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

                var bounds = Window.Current.Bounds;

                var newControl = await dispatcher.Dispatch(async() =>
                {
                    var newWindow     = Window.Current;
                    newWindow.Closed += (s, args) =>
                    {
                        _windows.TryRemove(parameter, out DispatcherWrapper ciccio);
                    };
                    newWindow.CoreWindow.Closed += (s, args) =>
                    {
                        _windows.TryRemove(parameter, out DispatcherWrapper ciccio);
                    };

                    var newAppView           = ApplicationView.GetForCurrentView();
                    newAppView.Consolidated += (s, args) =>
                    {
                        _windows.TryRemove(parameter, out DispatcherWrapper ciccio);
                        newWindow.Close();
                    };

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

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

                    var preferences        = ViewModePreferences.CreateDefault(ApplicationViewMode.CompactOverlay);
                    preferences.CustomSize = new Size(width, height);

                    await ApplicationViewSwitcher
                    .TryShowAsViewModeAsync(newAppView.Id, ApplicationViewMode.CompactOverlay, preferences);

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

                return(newControl);
            }
        }
Beispiel #6
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);
            }
        }
Beispiel #7
0
 public SecondaryViewSynchronizationContextDecorator(ViewLifetimeControl control, SynchronizationContext context)
 {
     _control = control ?? throw new ArgumentNullException(nameof(control));
     _context = context ?? throw new ArgumentNullException(nameof(context));
 }
Beispiel #8
0
        public async Task <ViewLifetimeControl> OpenAsync(Func <ViewLifetimeControl, UIElement> content, object parameter, double width, double height, ApplicationViewMode viewMode)
        {
            if (_windows.TryGetValue(parameter, out IDispatcherContext value))
            {
                var newControl = await value.DispatchAsync(async() =>
                {
                    var control    = ViewLifetimeControl.GetForCurrentView();
                    var newAppView = ApplicationView.GetForCurrentView();

                    var preferences        = ViewModePreferences.CreateDefault(viewMode);
                    preferences.CustomSize = new Size(width, height);

                    await ApplicationViewSwitcher
                    .TryShowAsViewModeAsync(newAppView.Id, viewMode, preferences);

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

                return(newControl);
            }
            else
            {
                var newView    = CoreApplication.CreateNewView();
                var dispatcher = new DispatcherContext(newView.Dispatcher);
                _windows[parameter] = dispatcher;

                var newControl = await dispatcher.DispatchAsync(async() =>
                {
                    var newWindow     = Window.Current;
                    newWindow.Closed += (s, args) =>
                    {
                        _windows.TryRemove(parameter, out _);
                    };
                    newWindow.CoreWindow.Closed += (s, args) =>
                    {
                        _windows.TryRemove(parameter, out _);
                    };

                    var newAppView           = ApplicationView.GetForCurrentView();
                    newAppView.Consolidated += (s, args) =>
                    {
                        _windows.TryRemove(parameter, out _);
                        newWindow.Close();
                    };

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

                    var control       = ViewLifetimeControl.GetForCurrentView();
                    control.Released += (s, args) =>
                    {
                        _windows.TryRemove(parameter, out _);
                        newWindow.Close();
                    };

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

                    var preferences        = ViewModePreferences.CreateDefault(viewMode);
                    preferences.CustomSize = new Size(width, height);

                    await ApplicationViewSwitcher.TryShowAsViewModeAsync(newAppView.Id, viewMode, preferences);

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

                return(newControl);
            }
        }
Beispiel #9
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);
            }
        }