locked
SwapChainBackgroundPanel/Page vs. Page/SwapChainBackgroundPanel

    Question

  • I'm not clear on the differences between these two approaches. In the XAML Direct3D Shooting Game sample's XAML file the sequence is Page->SwapChainBackgroundPanel. When I use VSExpress template to create a Direct2D App (XAML) app a SwapChainBackgroundPanel->Page sequence is used. It appears that I can only add one control to the Page using this template. 

    After reading this thread:

    http://social.msdn.microsoft.com/Forums/pl/wingameswithdirectx/thread/b5973bfc-88b4-4018-b02f-f442bf74b967

    I decided to make the Direct2D App (XAML) code look like the XAML Direct3D Shooting Game and simply swapped Page for SwapChainBackgroundPanel. When I do that, VSExpress complains that "The attachable property 'BottomAppBar' was not found in type 'Page'". There's also a compile error on the DirectXBase::Initialize but that could be fixed.

    What is the correct approach to creating a SwapChainBackgroundPanel XAML file? Should "Page" come before "SwapChainBackgroundPanel" or afterwards???

    Thanks

    Edit: is XAML required to create a SwapChainBackgroundPanel app? I don't want to go all the way down to a CoreWindow implementation because I'd like to use a few of the Metro UI controls (e.g. ListView).
    • Edited by henador Tuesday, July 24, 2012 4:36 AM
    Tuesday, July 24, 2012 4:21 AM

Answers

  • Either will work, however "Page->SCBP" is the recommended approach since it minimizes overdraw and enables some additional features (e.g. applying VisualStateManager states to the page).  The VS template should be updated in a future release.

    To convert the Direct2D template to use "Page->SCBP" you have to move the Page.BottomAppBar property so that it's still a child of the Page since BottomAppBar is a property of the Page type.  The overall markup structure should then look like:

    <Page ...>
      <SwapChainBackgroundPanel x:Name="mySCBP">
          <TextBlock />
      <SwapChainBackgroundPanel>
      <Page.BottomAppBar>
         <AppBar />
      </Page.BottomAppBar>
    </Page>

    To resolve the Initialize error you would then simply need to pass in a reference to the child SCBP instead of "this" in the Initialize call in DirectXPage.xaml.cpp since the SCBP isn't the root anymore.  You could do this by giving the SCBP a name in markup (as above) or by casting the Page->Content property to an SCBP.

    m_renderer->Initialize(
       Window::Current->CoreWindow,
       mySCBP, // Was: 'this'
       DisplayProperties::LogicalDpi
    );

    It has to be a XAML app to use both DirectX (via SCBP) and XAML Metro controls in the same app.

    • Marked as answer by henador Tuesday, July 24, 2012 5:43 PM
    Tuesday, July 24, 2012 4:44 PM

All replies

  • Either will work, however "Page->SCBP" is the recommended approach since it minimizes overdraw and enables some additional features (e.g. applying VisualStateManager states to the page).  The VS template should be updated in a future release.

    To convert the Direct2D template to use "Page->SCBP" you have to move the Page.BottomAppBar property so that it's still a child of the Page since BottomAppBar is a property of the Page type.  The overall markup structure should then look like:

    <Page ...>
      <SwapChainBackgroundPanel x:Name="mySCBP">
          <TextBlock />
      <SwapChainBackgroundPanel>
      <Page.BottomAppBar>
         <AppBar />
      </Page.BottomAppBar>
    </Page>

    To resolve the Initialize error you would then simply need to pass in a reference to the child SCBP instead of "this" in the Initialize call in DirectXPage.xaml.cpp since the SCBP isn't the root anymore.  You could do this by giving the SCBP a name in markup (as above) or by casting the Page->Content property to an SCBP.

    m_renderer->Initialize(
       Window::Current->CoreWindow,
       mySCBP, // Was: 'this'
       DisplayProperties::LogicalDpi
    );

    It has to be a XAML app to use both DirectX (via SCBP) and XAML Metro controls in the same app.

    • Marked as answer by henador Tuesday, July 24, 2012 5:43 PM
    Tuesday, July 24, 2012 4:44 PM
  • Thanks for providing a clear answer. I have things working now.

    I wasn't clear in my previous post but I had moved <Page.BottomAppBar> out of SCBP and the XAML editor still showed a blue squiggle under it and gave the warning. It turns out that the blue squiggle was some leftover artifact of a previous building of the code. When I cleaned the solution and rebuilt, the blues went away. This environment is extremely frustrating. It falls behind on the code when you edit the XAML text, keeps old errors/info squiggles around, etc. Not to mention how many times the embedded Blend Designer thing crashes and has to be restart (happens when I add or delete big chunks of XAML text, something I do all the time trying out stuff).

    Is the full VS2012 better than VSExpress with regards to my issues above? I'll get it anyway but I'll switch to it right now if will give me a more stable development environment.

    Tuesday, July 24, 2012 5:43 PM