locked
Navigate to the "Action" Page

    Question

  • Hello,
    I am creating a C++ DirectX and XAML App (Universal App). I've added a new page (the main menu), I've set it as the start page and now I cannot go to the default page, when I tap a textblock. It gives me an unhandeld exception.
    Code:
    this->Frame->Navigate(DirectXPage::typeid);

    Could be the problem with the swap chain panel?

    Thanks!

    Barna G.


    • Edited by Barna G Saturday, February 21, 2015 5:02 PM
    Friday, February 20, 2015 4:02 PM

Answers

  • Hello,

    Are you creating a new root frame in your App.xaml.cpp? It should look something like this:

    void App::OnLaunched(LaunchActivatedEventArgs^ e)
    {
    	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();
    
    		// Associate the frame with a SuspensionManager key.
    		SuspensionManager::RegisterFrame(rootFrame, "AppFrame");
    
    		// TODO: Change this value to a cache size that is appropriate for your application.
    		rootFrame->CacheSize = 1;
    
    		auto prerequisite = task<void>([](){});
    		if (e->PreviousExecutionState == ApplicationExecutionState::Terminated)
    		{
    			// Restore the saved session state only when appropriate, scheduling the
    			// final launch steps after the restore is complete
    			prerequisite = SuspensionManager::RestoreAsync();
    		}
    
    		prerequisite.then([=](task<void> prerequisite)
    		{
    			try
    			{
    				prerequisite.get();
    			}
    			catch (Platform::Exception^)
    			{
    				// Something went wrong restoring state.
    				// Assume there is no state and continue.
    				__debugbreak();
    			}
    
    			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(HubPage::typeid, e->Arguments);
    			}
    
    			// Place the frame in the current Window
    			Window::Current->Content = rootFrame;
    
    			// Ensure the current window is active
    			Window::Current->Activate();
    
    		}, task_continuation_context::use_current());
    	}
    	else
    	{
    		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
    			if (!rootFrame->Navigate(NewPage::typeid, e->Arguments))
    			{
    				throw ref new FailureException("Failed to create initial page");
    			}
    		}
    
    		// Ensure the current window is active
    		Window::Current->Activate();
    	}
    }

    I hope this helps,

    James


    Windows SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

    • Marked as answer by Barna G Saturday, February 21, 2015 5:10 PM
    Friday, February 20, 2015 10:11 PM
    Moderator

All replies

  • Hello,

    Are you creating a new root frame in your App.xaml.cpp? It should look something like this:

    void App::OnLaunched(LaunchActivatedEventArgs^ e)
    {
    	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();
    
    		// Associate the frame with a SuspensionManager key.
    		SuspensionManager::RegisterFrame(rootFrame, "AppFrame");
    
    		// TODO: Change this value to a cache size that is appropriate for your application.
    		rootFrame->CacheSize = 1;
    
    		auto prerequisite = task<void>([](){});
    		if (e->PreviousExecutionState == ApplicationExecutionState::Terminated)
    		{
    			// Restore the saved session state only when appropriate, scheduling the
    			// final launch steps after the restore is complete
    			prerequisite = SuspensionManager::RestoreAsync();
    		}
    
    		prerequisite.then([=](task<void> prerequisite)
    		{
    			try
    			{
    				prerequisite.get();
    			}
    			catch (Platform::Exception^)
    			{
    				// Something went wrong restoring state.
    				// Assume there is no state and continue.
    				__debugbreak();
    			}
    
    			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(HubPage::typeid, e->Arguments);
    			}
    
    			// Place the frame in the current Window
    			Window::Current->Content = rootFrame;
    
    			// Ensure the current window is active
    			Window::Current->Activate();
    
    		}, task_continuation_context::use_current());
    	}
    	else
    	{
    		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
    			if (!rootFrame->Navigate(NewPage::typeid, e->Arguments))
    			{
    				throw ref new FailureException("Failed to create initial page");
    			}
    		}
    
    		// Ensure the current window is active
    		Window::Current->Activate();
    	}
    }

    I hope this helps,

    James


    Windows SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

    • Marked as answer by Barna G Saturday, February 21, 2015 5:10 PM
    Friday, February 20, 2015 10:11 PM
    Moderator
  • Thank You very much!

    Barna G

    Saturday, February 21, 2015 5:11 PM