locked
Setting up an XAML overlay to an existing project

    Question

  • Hi,

    So, I have a DirectX (Direct2D with DirectWrite) game project, set up using the Direct2D Application project template. I want to use XAML for the menu and other UI features.

    I read this tutorial on DirectX + XAML interop, and I downloaded the D3D Shooting Game samples as well.

    I modified my low level DirectX code to be able to use the SwapChainBackgroundPane, but I've got stuck here, because I currently have no XAML file in my project to place the SwapChainBackgroundPane in. I tried to copy the App.xaml and the MainPage.xaml (and the codebehinds of course) from the interop sample to my project, and modify them, but I can't get rid of the main() function and startup using the App::App() method. If I delete the main(...) function I get an unresolved external error.

    Should I start the project again using a Metro Style App template, and copy the code, or can I work around this issue?
    Thanks for any help


    Wednesday, May 2, 2012 7:28 PM

Answers

  • The easiest approach for now is to just create a new C++ "Blank Application" in VS and paste your D2D source files into that.  This will ensure everything is set up correctly, and you can just add your SwapChainBackgroundPanel to BlankPage.xaml (or another XAML page you create).

    Main things to watch for when switching:

    1. Change the IDXGIFactory2::CreateSwapChainForCoreWindow call to CreateSwapChainForComposition
    2. Ensure the swap chain descriptor is setting the correct window bounds and scaling mode (the Direct2D template has different values than are required)
    3. Remove the old Run() method and instead use the methods in App.xaml.cpp
    4. In App::OnLaunched, just remove the Frame and Navigate calls and just directly set Window::Current->Content to your XAML page that contains your SwapChainBackgroundPanel
    Wednesday, May 2, 2012 9:04 PM

All replies

  • The easiest approach for now is to just create a new C++ "Blank Application" in VS and paste your D2D source files into that.  This will ensure everything is set up correctly, and you can just add your SwapChainBackgroundPanel to BlankPage.xaml (or another XAML page you create).

    Main things to watch for when switching:

    1. Change the IDXGIFactory2::CreateSwapChainForCoreWindow call to CreateSwapChainForComposition
    2. Ensure the swap chain descriptor is setting the correct window bounds and scaling mode (the Direct2D template has different values than are required)
    3. Remove the old Run() method and instead use the methods in App.xaml.cpp
    4. In App::OnLaunched, just remove the Frame and Navigate calls and just directly set Window::Current->Content to your XAML page that contains your SwapChainBackgroundPanel
    Wednesday, May 2, 2012 9:04 PM
  • Thanks for your answer
    Friday, May 4, 2012 6:16 PM