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); }
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); } }