这是来自implementing a shell上的Template10文章的App类中的建议代码:
public override Task OnInitializeAsync(IActivatedEventArgs args)
{
var nav = NavigationServiceFactory(BackButton.Attach, ExistingContent.Include);
Window.Current.Content = new Views.Shell(nav);
return Task.FromResult<object>(null);
}
将新的shell对象分配给Windows.Current.Content。
这是从the Template10 Secondary window example code:
打开辅助窗口(不带shell)的建议代码 var control = await NavigationService.OpenAsync(typeof(MySecondaryPage), null, Guid.NewGuid().ToString());
control.Released += Control_Released;
Windows.Current.Content与辅助窗口之间有什么关系?
答案 0 :(得分:2)
Windows.Current.Content与辅助窗口之间有什么关系?
实际上,NavigationService.OpenAsync
方法在内部调用ViewService.OpenAsync
。
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;
}
从上面的代码中,你可以得到应用程序的Window
(Singleton)没有被更改,当第二个窗口被激活时,Content
的{{1}}被替换为第二页。当前一个窗口激活时,Window
将返回第一页。您可以使用Windows.Current.Content
事件验证这一点。
Window.Current.Activated