2017-12-07 14 views
2

implementing a shell에 Template10 기사에서 앱 클래스에서 제안 된 코드는 다음과 같습니다보조 창을 연 후에 Windows.Current.Content의 값은 어떻게되어야합니까?

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

새로운 쉘 객체는 Windows.Current.Content에 할당됩니다.

이것은

var control = await NavigationService.OpenAsync(typeof(MySecondaryPage), null, Guid.NewGuid().ToString()); 

       control.Released += Control_Released; 

Windows.Current.Content 이차 윈도우 사이의 관계는 무엇 the Template10 Secondary window example code: 행 (하지 쉘)와 보조 윈도우를 열기위한 제안 코드?

답변

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 두 번째 창이 활성화되면 (싱글)이 변경되지 않은, WindowContent가 두 번째 페이지로 대체되었습니다. 그리고 이전 창이 활성화되었을 때 Windows.Current.Content는 주먹 페이지를 되돌릴 것입니다. 그리고 Window.Current.Activated 이벤트로이를 확인할 수 있습니다.

Window.Current.Activated += Current_Activated; 

private void Current_Activated(object sender, Windows.UI.Core.WindowActivatedEventArgs e) 
{ 
// check the sender 
} 
+0

감사합니다.이 질문에 대한 답변입니다. –