Question

I've read on few places already, that it's possible to combine XNA and WPF. What I personally need is a game/map editor, which would actually be the game itself (would have the engine running in background), because map system writes serialized versions of objects to XML, which are later loaded.

My problem is that I want an standard app, that'd run the engine in the background, and create game assets as user creates them from the frontend, and later on serialize them and put into XML.

This would also come in handy, if it's possible to run WPF from game, for UI, if anyone had any experiences with this, I'd appreciate if he/she'd share it.

Shortly: how can I make WPF (or winforms) app, that has XNA code running in one of it's control, and in background?

Was it helpful?

Solution

I don't know of anyone embedding WPF controls into an XNA game window. This would be a very difficult thing due to the fact that they both use DirectX for rendering. Since you're allowed to do anything with XNA, that would make WPF overlays and whatnot very difficult. If you're looking for in-game controls, try out NeoForce.

Going the other way is much simpler (read: actually supported). I know that you can embed an XNA window into a a Windows user control -- see this for a quick demo. I have used a technique similar to that to make an editor for my game. Unfortunately, integrating directly with WPF would be troublesome as well (due to the same reasons you can't put WPF controls in an XNA GameWindow). However, you could embed that control onto a WindowsFormsHost and that might work nicely (haven't ever tried it).

Obviously, this will not work on Xbox 360, since WinForms and WPF aren't available there, but you typically don't put your editor on 360 anyway.

ALSO: I hope you're not using XML serialization to load your game files at run time -- that's what the XNA Content Pipeline is for.

OTHER TIPS

I posted this in another question, but there seem to be a lot of questions about how to integrate an XNA-like control in WPF. I read Nick Gravelyn's Blog and the Arcane.Xna post, and managed to develop something similar to both that completely parallels Microsoft.Xna.Framework.Game while providing WPF compatibility. You can even instantiate multiple Game classes, if you desire:

https://xnaml.codeplex.com/

Have you tried creating a WPF application and then adding the XNA references to it?

You should be able to do that and then create a class that inherits from GameObject and put that into your WPF application.

WPF has direct access to a lot of DirectX as well as cameras and a lot of the things you'd need to just write the game in WPF. Maybe just use XNA methods for some of your calculations.

I can definitely see more than one way to skin this cat.

Check out this thread on the XNA forums: http://forums.xna.com/forums/p/1122/6455.aspx

It will 1) give you an idea of why this integration is so troublesome and 2) show you how to host an XNA control on a WPF form (look for ZMan's posts). As far as using WPF inside of XNA for GUI rendering, I wouldn't hold my breath. There is really very little reason for Microsoft to go out of its way to support this, and console GUI experiences son't really line up that well with an API meant for point and click.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top