title: Vortice.Windows: How to call SetSwapChain() in WinUI?
body: <p>I'm trying to initialize my SwapChainPanel as described <a href="https://docs.microsoft.com/en-us/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.controls.swapchainpanel?view=windows-app-sdk-1.1#initializing-a-swapchainpanel-element" rel="nofollow noreferrer">in the documentation</a> by calling <code>ISwapChainPanelNative.SetSwapChain()</code>.</p>
  <p>However, I'm struggling to convert my <code>Microsoft.UI.Xaml.Controls.SwapChainPanel</code> to <code>ISwapChainPanelNative</code>.</p>
  <p>How can I get a <code>ISwapChainPanelNative</code> from my WinUI <code>SwapChainPanel</code>?</p>
  <p>What I've tried so far:</p>
  <pre class="lang-cs prettyprint-override"><code>private void AssociateSwapChainPanel(
      Microsoft.UI.Xaml.Controls.SwapChainPanel swapChainPanel,
      Vortice.DXGI.IDXGISwapChain3 swapChain)
  {
      IUnknown swapChainPanelUnknown = swapChainPanel as IUnknown; // null
      IInspectable swapChainPanelInspectable = swapChainPanel as IInspectable; // null
      var swapChainPanelNative = swapChainPanel as Vortice.WinUI.ISwapChainPanelNative; // Doesn't compile
      var swapChainPanelNative = swapChainPanelInspectable.ObjRef.AsInterface&lt;Vortice.WinUI.ISwapChainPanelNative&gt;(); // Exception
      var swapChainPanelNative = WinRT.CastExtensions.As&lt;Vortice.WinUI.ISwapChainPanelNative&gt;(swapChainPanel); // Exception
      var swapChainPanelNative = (Vortice.WinUI.ISwapChainPanelNative)(object)swapChainPanel; // Exception
  </code></pre>