Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use XNA in WPF?

Tags:

c#

wpf

xna

So... I want to make a game, and I want to write it in C#. In the past, I've made a mario clone using C++ and OpenGL. I quite like OpenGL, but I don't know how well it's supported inside C#/WPF. Also, it might be beneficial to use an actual game library? I guess XNA is the game library for C#, so maybe I'll invest a bit of time learning that.

However, I want to use WPF form controls for my level editor... is there any way that I can embed an XNA (DirectX?) window inside a WPF app?

Specifically, I don't need any buttons or things inside the XNA/DirectX widget, just around it, so no mixing required...just need to get a graphics widget in my WPF form.

like image 773
mpen Avatar asked Nov 08 '10 04:11

mpen


3 Answers

Nick Gravelyn explains how to do it on his blog.

Although, if it's just for an editor, you may find using WinForms is easier and better supported.

like image 134
Andrew Russell Avatar answered Oct 23 '22 19:10

Andrew Russell


WPF uses DirectX, and you can do direct "interop" here is a codeProject article on the subject. Here is an article i dug up where the author is using win-forms and WPF controls in an XNA project. Might be worth a look for you.

like image 26
Muad'Dib Avatar answered Oct 23 '22 18:10

Muad'Dib


First of all, you should ask this on gamedev.stackexchange.com. But I've seen a tutorial embedding XNA.

You should check this question and this page. They are on Windows Forms, but they'll help.

Also check this and this articles.

Keep in mind one thing. XNA is meant to be used for the whole game, integration would be useful on making level editors like you say, but not for a full game.

like image 30
David Conde Avatar answered Oct 23 '22 19:10

David Conde