locked
Why is DirectXPage::Frame NULL in a Direct2D App (XAML) project

    Question

  • I am adding page navigation capability to my app, which is created using the Direct2D App (XAML) prototype. Whenever the code

    	this->Frame->Navigate(Windows::UI::Xaml::Interop::TypeName(BasicPage::typeid));
    

    is executed, an exception is thrown. With some debugging, I find this->Frame is NULL, which triggers the exception.

    void DirectXPage::OnPreviousColorPressed(Object^ sender, RoutedEventArgs^ args)
    {
    	Windows::UI::Xaml::Controls::Frame^ frame = this->Frame;
    	// frame is NULL so an exception is thrown
    	frame->Navigate(Windows::UI::Xaml::Interop::TypeName(BasicPage::typeid));
    
    	this->Frame->Navigate(Windows::UI::Xaml::Interop::TypeName(BasicPage::typeid));
    	m_renderer->BackgroundColorPrevious();
    	m_renderNeeded = true;
    }
    

    I created another project using the Blank Application (XAML) template, and found the this->Frame->Navigate works well. Could someone tell me why is the DirectXPage::Frame is NULL. My issue can be reproduced with following steps:

    1, Create a project using the Direct2D App (XAML) template.

    2, Add a basic page named BasicPage.xaml.

    3, Add the line " this->Frame->Navigate(Windows::UI::Xaml::Interop::TypeName(BasicPage::typeid));" to the function DirectXPage::OnPreviousColorPressed.

    4, Run the app, bring out the bottom AppBar and click the "Previous Color" button.

    Wednesday, July 10, 2013 12:40 PM

All replies