Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6805975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:39:12+00:00 2026-05-26T19:39:12+00:00

I’m trying to host an XNA game inside a WPF window using the Windows

  • 0

I’m trying to host an XNA game inside a WPF window using the Windows Forms host control. I’ve got a weird problem that a “Phantom” window is created when I run the game. It is created exactly at the first call to game’s Update method exits.

Here is the Update code, the default one from a new XNA project:

    protected override void Update(GameTime gameTime)
    {
        // Allows the game to exit
        if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            this.Exit();

        // TODO: Add your update logic here

        base.Update(gameTime);
    }

The window is created after I step from the last curly brace at the very bottom. (yes, weird to have it NOT in base.Update but the after the } after it.)

I have a Windows Forms host as I’ve said, with the code below:

The relevant XAML is here (I’ve obviously got the Forms namespace etc. set up so no need to paste here):

<WindowsFormsHost Margin="12" Name="windowsFormsHost1">
    <forms:Panel x:Name="p"></forms:Panel>
</WindowsFormsHost>

and in codebehind:

    private void Window_Loaded(object sender, RoutedEventArgs e)
    {
        Viewer v = new Viewer(p.Handle);
        v.Run();
    }

where the Viewer is my Game class (from XNA), with:

    public Viewer(IntPtr handle)
    {
        graphics = new GraphicsDeviceManager(this);
        Content.RootDirectory = "Content";
        panelHandle = handle;
        graphics.PreparingDeviceSettings += new EventHandler<PreparingDeviceSettingsEventArgs>(graphics_PreparingDeviceSettings);
    }

    void graphics_PreparingDeviceSettings(object sender, PreparingDeviceSettingsEventArgs e)
    {
        e.GraphicsDeviceInformation.PresentationParameters.DeviceWindowHandle = panelHandle;
    }

This technique is from a blog post I’ve found a few days ago (I can’t find it again now, it is EXACTLY the same way — with the exception that the post was old and doesn’t have the issue I’m having).

The problem is that, I build and run, but along with my “normal” window, there is a phantom window created. In my main window, XNA renders correctly. But the phantom window (the Window title is my assembly’s name), doesn’t have anything in it, is not resizable, cursor doesn’t render inside it, and it acts like the main window in the sense that when I minimize this window, my main window stops rendering the XNA content until I un-minimize that phantom window. My program doesn’t quit until I close BOTH windows. (If I close the phantom only, my main window, as you guess, stops rendering my XNA content). I tried iterating over my application windows, with ‘App.Current.Windows’, and all I’ve got is my main window listed there, that’s why I’m calling that semi-responsive window the “phantom” window. It is not visible in my object model in WPF.

When I wrote “XNA WPF phantom window”, the first I’ve got was this: WPF: How to determine the origin of a phantom window?

So I went and tried the Snoop. But Snoop probably also relies on the Windows iteration, and it also doesn’t see any extra window there. I use the crosshair-drag feature (you drag the cursor around the screen and Snoop tells which process and window it belongs to), and Snoop tells that the Phantom Window is actually my MainWindow. But my MainWindow is ALSO the same window, according to Snoop. So this phantom is somewhat closely related (or maybe a “child”?) of my MainWindow instance, but I need a way to close it (or at least, hide it).

Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T19:39:13+00:00Added an answer on May 26, 2026 at 7:39 pm

    The two good ways of embedding XNA in WPF that I know of are in this post (one is described in the post itself, the other is described in the first link in the post):

    http://blogs.msdn.com/b/nicgrave/archive/2011/03/25/wpf-hosting-for-xna-game-studio-4-0.aspx

    Both have code samples and I’ve used the WriteableBitmap version before with good results. (I was creating a development tool that didn’t need to show anything larger than 384×384 so FPS was acceptable; if you need high FPS with a large back buffer (e.g. 800×600, 720p, etc.) you’ll definitely want to use the HwndHost method).

    I’d recommend trying whichever one of those two best fits your needs. When you try to use the window XNA creates, XNA’s WinForms window expects to be a top level window. I’ve tried messing around with solutions such as what you’ve posted in the past but have never gotten beyond the phantom window issue.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.