A getting started template for creating XAML/DX apps using C++ and the SwapChainBackgroundPanel

This post comes courtesy of Wayne Ransier.

Start a XAML/C++ project in Visual Studio 2012 with the default Blank Template and replace the generated <Grid> element with a <SwapChainBackgroundPanel>

<SwapChainBackgroundPanel x:Name="DXSwapChainPanel">
</SwapChainBackgroundPanel>
If you build the solution now, the code compiles but the app crashes at runtime. The fix for the crash is simple.
Replace the OnLaunched method of your App class with the below code
void App::OnLaunched(Windows::ApplicationModel::Activation::LaunchActivatedEventArgs^ args)
{
    m_mainPage = ref new MainPage();    
    Window::Current->Content = m_mainPage;
    Window::Current->Activate();
}

 

The code to replace the OnLaunched method of the App class is missing from the step by step application tutorial of the DrawIt application.

You can get the complete details about why the crash happens here.
A simple project template with this fix applied can be found here.
Copy this project template (the zip file) to “C:\Users\<username>\Documents\Visual Studio 2012\Templates\ProjectTemplates” and re-start Visual Studio 2012.
A new template with the name SCBPCppProject will be listed when you select Visual C++ project type in Visual Studio 2012.
Another nifty tip to keep in mind and this is obtained from the DrawIt sample from “Modern C++ and Windows Store apps” book.
There are a few styles that I have created for the ApplicationBar and placed them in Styles.xaml. In the sample I do not use the default generated styles from StandardStyles.xaml.
You can see the change in app.xaml for the DrawIt project.
<ResourceDictionary.MergedDictionaries>

    <!-- 
        Styles that define common aspects of the platform look and feel
        Required by Visual Studio project and item templates
     -->
    <ResourceDictionary Source="Styles.xaml"/>
</ResourceDictionary.MergedDictionaries>

 

Merging only the resources your application requires, into the Resource Dictionary is a nifty optimization.
A version of the sample that supports multi-touch can be downloaded here.
-Sridhar