Graphics Reference
In-Depth Information
8.
Open the new XAML file in the designer (
Shift
+
F7
), and change the
Page
tag to
SwapChainPanel
, as shown in the following screenshot:
Changing the Page element to SwapChainPanel
9. Now, open the C# code for the XAML file (
F7
), and change the class we inherit to
SwapChainPanel
instead of
Page
.
public sealed partial class D3DPanel :
SwapChainPanel
{
...
}
10. Within the default constructor, we will initialize a new instance of a
D3DApp
class
(that inherits from the
D3DAppSwapChainPanelTarget
class), and create the
rendering loop using the
Windows.UI.Xaml.Media.CompositionTarget.
Rendering
event.
D3DApp d3dApp;
public D3DPanel()
{
this.InitializeComponent();
// Only use Direct3D if outside of the designer
if (!Windows.ApplicationModel.DesignMode
.DesignModeEnabled)
{
d3dApp = new D3DApp(this);
d3dApp.Initialize();
CompositionTarget.Rendering +=
CompositionTarget_Rendering;
}
}
void CompositionTarget_Rendering(object sender, object e)
{
if (d3dApp != null)
d3dApp.Render();
}