2016-07-28 3 views
0

프로토콜 활성화를 추가해야하는 UWP 테스트 App에서 작업하고 있습니다. 활성화 논리는 클래스 라이브러리에 기록되며 UWP 테스트 App에 참조로 추가됩니다. 문제는 테스트 응용 프로그램의 OnActivated 이벤트에 논리를 작성하면 제대로 작동하지만 클래스 라이브러리의 함수에 동일한 논리가 작성되어이 함수가 App.xaml.cs OnActivated 이벤트에서 호출 될 때 문제가 발생합니다. 이 OnActivated 이벤트는 무한 루프에서 호출됩니다.UWP의 프로토콜 활성화

OnActivated 이벤트에서 새 프레임을 만들어야합니까?

답변

3

OnActivated가 호출되면 이미 초기화되었는지 여부를 확인해야합니다 (OnLaunched가 호출되지 않았기 때문에). - 프레임을 만들고 활성화하지 않은 경우 활성화하십시오. 일반적으로 OnLaunchedOnActivated 이벤트 사이에서이 초기화 코드를 공유 할 수 있습니다.

protected override void OnActivated(IActivatedEventArgs e) 
{ 
    Frame rootFrame = Window.Current.Content as Frame; 

    // Do not repeat app initialization when the Window already has content 
    if (rootFrame == null) 
    { 
     // Create a Frame to act as the navigation context 
     rootFrame = new Frame(); 

     rootFrame.NavigationFailed += OnNavigationFailed; 

     if (e.PreviousExecutionState == ApplicationExecutionState.Terminated) 
     { 
      //TODO: Load state from previously suspended application 
     } 

     // Place the frame in the current Window 
     Window.Current.Content = rootFrame; 
    } 

    // 
    // Handle protocol activation here 
    // 

    // Ensure the current window is active 
    Window.Current.Activate(); 
} 
관련 문제