title: How can I programmatically replace the window view to a XAML page in a WinJS app?
body: <p>I have a cordova application that has a plugin that uses OpenGL/DirectX that needs to take over the app window. I have everything working great, up until I go to actually set the contents of the app window. When I go to instantiate the XAML page I get an error about not being on the correct thread:</p>
  
  <blockquote>
    <p>RPC_E_WRONG_THREAD The application called an interface that was marshalled for a different thread.</p>
  </blockquote>
  
  <p>I've seen a few people say this isn't possible, but I feel like it has to be possible in someway, unless the window is sandboxed or something. I'm also thinking the problem may be that the XAML backend service/framework/whatever isn't setup in a WinJS app? In which case is there some way to manually set it up?</p>
  
  <p>I'd appreciate any help at all, and at least an explanation as to why it's not possible. I'm pretty new to Windows programming and I appreciate knowing why something can't be done.</p>
  
  <p>Thanks!</p>
  
  <p>P.S.</p>
  
  <p>I've also tried to run the code that creates the XAML class inside of a dispatcher:</p>
  
  <pre><code>Windows::ApplicationModel::Core::CoreApplication::MainView-&gt;CoreWindow-&gt;Dispatcher-&gt;RunAsync
  </code></pre>
  
  <p>Here is my code:</p>
  
  <pre><code>void MyComponent::doStuff(){
      if (m_directXPage == nullptr)
      {
          try
          {
              m_directXPage = ref new DirectXPage();
          }
          catch (const std::exception&amp; e)
          {
              e.what();
          }
  
      }
  
      // Place the page in the current window and ensure that it is active.
      Window::Current-&gt;Content = m_directXPage;
      Window::Current-&gt;Activate();
  }
  </code></pre>