2016-06-14 4 views
0

저는 Windows 10 UWP 응용 프로그램을 처음 사용하며 현재 응용 프로그램에서 다양한 탐색 기법을 시도하고 있습니다. UWP 애플 리케이션에서 뒤로 버튼 기능을 검색했지만 위선적으로 '제공된 코드'를 어디에 두어야하는지, 어떻게 실행해야하는지 이해하지 못하는 것 같습니다. 나는 또한 독자적으로 시도했지만 Visual Studio에서 식별자를 찾을 수 없다는 여러 가지 오류가 발생합니다.UWP 뒤로 버튼 및 이벤트 처리기 - C++

첫 번째 코드는 다음과 같습니다 코드의

Windows::UI::Core::SystemNavigationManager::GetForCurrentView()-> 
    BackRequested += ref new Windows::Foundation::EventHandler< 
    Windows::UI::Core::BackRequestedEventArgs^>(
    this, &App::App_BackRequested); 

두 번째 부분은 다음과 같습니다

void App::App_BackRequested(
    Platform::Object^ sender, 
    Windows::UI::Core::BackRequestedEventArgs^ e) 
    { 
    Frame^ rootFrame = dynamic_cast<Frame^>(Window::Current->Content); 
    if (rootFrame == nullptr) 
    return; 

    // Navigate back if possible, and if the event has not 
    // already been handled. 
    if (rootFrame->CanGoBack && e->Handled == false) 
     { 
      e->Handled = true; 
      rootFrame->GoBack(); 
     } 
    } 

내가 내 UWP 응용 프로그램에서이 코드를 구현 어떻게이 문제에 나에게 도움을 가르쳐주세요. 감사합니다

출처 : https://msdn.microsoft.com/en-us/library/windows/apps/mt465734.aspx

+0

앱이 "빌드"되었을 때 첫 번째 비트가 설치 중에 실행되어야하고 두 번째 비트는 실제로 뒤로 버튼이 클릭 될 때 실행되어야합니다. – ocket8888

답변

0

그것은 다음과 같이해야합니다 :

이 App.xaml.cpp 클래스의 OnLaunched 방법 : OnLaunched에서

void App::OnLaunched(Windows::ApplicationModel::Activation::LaunchActivatedEventArgs^ e) 
{ 
#if _DEBUG 
// Show graphics profiling information while debugging. 
if (IsDebuggerPresent()) 
{ 
    // Display the current frame rate counters 
    DebugSettings->EnableFrameRateCounter = true; 
} 
#endif 
auto rootFrame = dynamic_cast<Frame^>(Window::Current->Content); 

// Do not repeat app initialization when the Window already has content, 
// just ensure that the window is active 
if (rootFrame == nullptr) 
{ 
    // Create a Frame to act as the navigation context and associate it with 
    // a SuspensionManager key 
    rootFrame = ref new Frame(); 

    rootFrame->NavigationFailed += ref new Windows::UI::Xaml::Navigation::NavigationFailedEventHandler(this, &App::OnNavigationFailed); 

    if (e->PreviousExecutionState == ApplicationExecutionState::Terminated) 
    { 
     // TODO: Restore the saved session state only when appropriate, scheduling the 
     // final launch steps after the restore is complete 

    } 


    if (e->PrelaunchActivated == false) 
    { 
     if (rootFrame->Content == nullptr) 
     { 
      // When the navigation stack isn't restored navigate to the first page, 
      // configuring the new page by passing required information as a navigation 
      // parameter 
      rootFrame->Navigate(TypeName(MainPage::typeid), e->Arguments); 
     } 
     // Place the frame in the current Window 
     Window::Current->Content = rootFrame; 
     // Ensure the current window is active 
     Window::Current->Activate(); 
    } 
} 
else 
{ 
    if (e->PrelaunchActivated == false) 
    { 
     if (rootFrame->Content == nullptr) 
     { 
      // When the navigation stack isn't restored navigate to the first page, 
      // configuring the new page by passing required information as a navigation 
      // parameter 
      rootFrame->Navigate(TypeName(MainPage::typeid), e->Arguments); 
     } 
     // Ensure the current window is active 
     Window::Current->Activate(); 
    } 
} 

Windows::UI::Core::SystemNavigationManager::GetForCurrentView()-> 
    BackRequested += ref new Windows::Foundation::EventHandler< 
    Windows::UI::Core::BackRequestedEventArgs^>(
     this, &App::App_BackRequested); 
} 

지금 :

그냥 끝 전에 먼저 조각을 붙여 넣어야합니다 메서드를 붙여 넣으십시오.

void App::App_BackRequested(
Platform::Object^ sender, 
Windows::UI::Core::BackRequestedEventArgs^ e) 
{ 
Frame^ rootFrame = dynamic_cast<Frame^>(Window::Current->Content); 
if (rootFrame == nullptr) 
    return; 

// Navigate back if possible, and if the event has not 
// already been handled. 
if (rootFrame->CanGoBack && e->Handled == false) 
    { 
    e->Handled = true; 
    rootFrame->GoBack(); 
    } 
} 

다음을 추가해야합니다. App.xaml.h 낮은 코드 : 밀봉

심판 클래스 응용 프로그램은 (비주얼 스튜디오가 자동으로 추가 할 수 있습니다) : { 보호 : 가상 무효가 OnLaunched (윈도우 :: ApplicationModel :: 활성화 :: LaunchActivatedEventArgs^전자) 재정의 ;

void App_BackRequested(Platform::Object^sender, Windows::UI::Core::BackRequestedEventArgs^e); 

internal: 
    App(); 

private: 
    void OnSuspending(Platform::Object^ sender, Windows::ApplicationModel::SuspendingEventArgs^ e); 
    void OnNavigationFailed(Platform::Object ^sender, Windows::UI::Xaml::Navigation::NavigationFailedEventArgs ^e); 
}; 

희망이 도움이 될 것입니다.

+0

예, 이미 완료 한 것입니다. . –

0

내가 바로 어떻게 든 그걸 얻기 위해 관리는, 첫 번째 코드는 "OnLaunched"이벤트에서 코드 숨김 파일 App.xaml에 넣어했다. 두 번째 코드는 위 파일의 마지막에 놓였으며 앞으로 선언은 헤더 파일에 넣어졌습니다.