예제 #1
0
 public async Task CloseViewAsync()
 {
     int currentId = ApplicationView.GetForCurrentView().Id;
     await ApplicationViewSwitcher.SwitchAsync(MainViewId, currentId, ApplicationViewSwitchingOptions.ConsolidateViews);
 }
예제 #2
0
 public async Task SwitchToMainViewAsync()
 {
     await ApplicationViewSwitcher.SwitchAsync(this.MainViewId);
 }
예제 #3
0
        public override void Run()
        {
            UIElement main;

            try
            {
                string layoutString = layoutSetting.XamlString.Value;
                layoutFactory = () => (LayoutRoot)XamlReader.Load(layoutString);
                var layout = layoutFactory();
                main = new MainView {
                    MainContent = layout.MainWindow.LoadContent()
                };
                viewIds = layout.SubWindows.Select(x => x.Id).Append("Settings").ToArray();
            }
            catch
            {
                layoutFactory = () =>
                {
                    var l = new LayoutRoot();
                    Application.LoadComponent(l, new Uri("ms-appx:///Layout/Default.xaml"));
                    return(l);
                };
                var layout = layoutFactory();
                main = new MainView {
                    MainContent = layout.MainWindow.LoadContent()
                };
                viewIds = layout.SubWindows.Select(x => x.Id).Append("Settings").ToArray();
            }

            InitWindow();
            new UISettings().ColorValuesChanged += async(sender, _) =>
            {
                foreach (var view in CoreApplication.Views)
                {
                    await view.Dispatcher.RunAsync(CoreDispatcherPriority.High, () =>
                                                   ApplicationView.GetForCurrentView().TitleBar.ButtonForegroundColor = sender.GetColorValue(UIColorType.Foreground));
                }
            };

            var style = new Style
            {
                TargetType = typeof(ViewPresenter),
            };

            style.Setters.Add(new Setter(ViewPresenter.ViewSourceProperty, Views));
            Application.Current.Resources[typeof(ViewPresenter)]        = style;
            Application.Current.Resources[ViewSwitcher.SwitchActionKey] = new Action <string>(async viewId =>
            {
                if (applicationViewIds.TryGetValue(viewId, out int id))
                {
                    await ApplicationViewSwitcher.SwitchAsync(id);
                    return;
                }

                if (viewIds.Contains(viewId))
                {
                    var coreView = CoreApplication.CreateNewView();
                    await coreView.Dispatcher.RunAsync(CoreDispatcherPriority.High, () =>
                    {
                        CoreApplication.GetCurrentView().Properties["Id"] = viewId;
                        var view = ApplicationView.GetForCurrentView();
                        applicationViewIds[viewId] = view.Id;

                        InitWindow();
                        if (viewId == "Settings")
                        {
                            Window.Current.Content = new SettingsView(CreateSettingViews(), localizationService);
                        }
                        else
                        {
                            Window.Current.Content = new SubView {
                                ActualContent = layoutFactory()[viewId].LoadContent()
                            }
                        };

                        view.Consolidated += (s, e) =>
                        {
                            Window.Current.Content = null;
                            applicationViewIds.TryRemove(viewId, out _);
                        };

                        Window.Current.Activate();
                    });
                    await ApplicationViewSwitcher.TryShowAsStandaloneAsync(applicationViewIds[viewId]);
                }
            });

            Window.Current.Content = main;
            gameProvider.Enabled   = true;
        }
예제 #4
0
 private async void OnUnlockClick(object sender, Windows.UI.Xaml.RoutedEventArgs e)
 {
     var context = ServiceLocator.Current.GetService <IContextService>();
     await ApplicationViewSwitcher.SwitchAsync(context.MainViewID);
 }
 private async void HideView_Click(object sender, RoutedEventArgs e)
 {
     await ApplicationViewSwitcher.SwitchAsync(mainViewId,
                                               ApplicationView.GetForCurrentView().Id,
                                               ApplicationViewSwitchingOptions.ConsolidateViews);
 }
 private async void GoToMain_Click(object sender, RoutedEventArgs e)
 {
     await ApplicationViewSwitcher.SwitchAsync(mainViewId);
 }
예제 #7
0
        public async Task <ViewLifetimeControl> OpenAsync(Type page, object parameter = null, string title = null,
                                                          Size size = default, 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;
                    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, ViewSizePreference.UseHalf);
                    //newAppView.TryResizeView(new Windows.Foundation.Size(360, bounds.Height));
                    newAppView.TryResizeView(size);

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

                return(newControl);
            }
        }