Dec 5, 2009 at 5:04 PM

Is it possible to use Balder with WPF?

Dec 5, 2009 at 6:09 PM

Not at the moment. The architecture has been built for supporting more platforms, and WPF is the one that would take the least amount of time. 

I guess with the current feature set, it wouldn't take more than a week or so to get the support up and running. 

That being said, I can't guarantee for when WPF will get focus, it all depends on demand, I guess. 

Feb 2, 2011 at 2:04 AM

1 more vote for WPF... as i'm developing for Microsoft Surface-type applications... it's sad to see WPF getting neglected.... :(

Feb 2, 2011 at 6:46 AM

I've started desktop implementation - so we'll get there. What is your timeframe?

Feb 2, 2011 at 12:22 PM

hi, thanks for the reply...

actually i just want to implement this http://maps.esri.com/sldemos/terrainmap/default.html in wpf...

Looking at the code, it is using the Heightmap class... so if i can just use this class, i would be happy...

Do you know if there is any equivalent class in WPF3D?

THanks so much!!

Feb 2, 2011 at 2:40 PM


I'm not too familiar with WPF3D. 

But you would be happy with Balder using something else - like XNA in the background and presenting it as a control that you can place things on top of. Like it works with Silverlight today? 

Feb 2, 2011 at 5:27 PM

To be a bit more accurate. It would give you full 3D in WPF but not utilizing the built in 3D capabilities of WPF, but rather use XNA and render to the surface of WPF directly - but still have the capabilities of putting things on top of the rendered surface. 


Feb 2, 2011 at 5:33 PM

Yes that would be excellent... i believe XNA performs better than WPF's 3D.... i actually have 2 weeks' time frame to show a demo... if you can implement WPF compatibility by then.. it would be great!!

anyway.. i think this project is really excellent... as i have no knowledge in XNA.... it gives me ability to still use it transparently... thanks!

Feb 2, 2011 at 6:25 PM

FYI, that's basically how the Torque Game Engine worked.  The 3D Window was actually just a GUI Control.

Feb 2, 2011 at 7:36 PM

I have basic XNA up and running. I can't guarantee anything. Give me a couple of days and I'll get back to you, so you don't sit around waiting for something I might not be able to get up and running for you in that timeframe.

Feb 9, 2011 at 8:33 PM

Hi, any chance of seeing the WPF assembly this weekend? :) My demo is next week and i really want to show it on WPF... thanks so much... just need the heightmap capability.... >.<

Feb 12, 2011 at 9:12 AM

I'm closing in - I've got it compiling at least with WPF and XNA mixed. All I need to do now is to get the pixeldata into a bitmap source. Hopefully I'll get this ready over the weekend. No guarantees. 

Sorry for the late answer - crazy crazy days this week.

Feb 15, 2011 at 11:01 AM

Hi is the latest files at the Source Code page usable? Actually i tried compiling which was ok.. but when running the testapp, it cannot create an instance of the "Game".... 

Anyway, thanks for the effort..... still looking forward to the release....

Feb 15, 2011 at 7:28 PM


very very very close. In fact, I've got it all running except that it won't display anything. I don't have any time left this week. I've just pushed how far I've gotten. It runs, but there is only blackness. If you have time, you can take a look at the CopyFromRenderTargetToWriteableBitmap() method in the Display.cs file located inside Balder.Display.Xna folder in the Balder.WPF project (Open the Balder_WPF.sln in Solutions).

There is one limitation to the implementation - the Width and Height are for now hardcoded. I have to figure out a better way of initializing things, there is a timing issue when the GraphicsDevice needs to be made available.

Other than that you should in theory be able to render things with WPF.


Sorry I didn't get as far as I had hoped.

Feb 17, 2011 at 10:27 AM

no problem...

i think i dun have the capability to modify the code... i will still wait for your official release....


Feb 17, 2011 at 1:00 PM

The great job! Expecting more resuls...


Feb 19, 2011 at 4:18 AM
Edited Feb 19, 2011 at 4:19 AM

I got it to work by changing the Render/WindowRender function in Source/Balder/Display/Xna/Display.cs as follows:


_spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend);
_spriteBatch.Draw(_texture, new Rectangle(0, 0, size, size), new Microsoft.Xna.Framework.Color(0xff, 0xff, 0xff, 0xff));


i.e. use the render target. ;)


Feb 19, 2011 at 4:31 AM

Also, if you're using WriteableBitmap.WritePixels, then you don't need to call Lock, AddDirtyRect, or Unlock. This is done internally in WriteableBitmap.WritePixelsImpl - check with Reflector. So CopyFromRenderTargetToWriteableBitmap becomes:

private void CopyFromRenderTargetToWriteableBitmap()
    _writeableBitmap.WritePixels(_fullScreenRect, _pixels, 800 * 4, 0);

Feb 19, 2011 at 6:17 AM

Fool: You're absolutely right. I was blind - didn't see that.  Thanks a lot. 

Feb 19, 2011 at 6:37 AM

Also, one needs to swap components since XNA is RGBA and WPF is BGRA. 

I've just pushed a version that works with WPF. The work is not 100% done yet, but at least one can start playing around with it. All you need to do is get the latest source code and open the Balder_Wpf.sln file in the Solutions folder and build it and pick up the binaries from there.

Feb 20, 2011 at 10:28 AM
Edited Feb 20, 2011 at 10:40 AM


sorry but i've got a compile error in Release mode:

Error 8 'Balder.Execution.Runtime.Platform' is a 'property' but is used like a 'type' ........\Source\Balder\Execution\Runtime.cs 89 43 Balder.WPF

Feb 20, 2011 at 12:05 PM

Sorry about that. I forgot to test it with release - was in a hurry and just checked in the Dbug version.


Fixed it now, compiles in release.

Feb 20, 2011 at 4:23 PM

hi thanks for the fast reply

i encountered a runtime problem with my own WPF app... when creating the HeightMap object, an exception was thrown

System.ArgumentNullException was caught  Message=The GraphicsDevice must not be null when creating new resources.Parameter name: graphicsDevice  Source=Microsoft.Xna.Framework.Graphics  ParamName=graphicsDevice  StackTrace:       at Microsoft.Xna.Framework.Graphics.Effect.CreateEffectFromCode(GraphicsDevice graphicsDevice, Byte[] effectCode)       at Microsoft.Xna.Framework.Graphics.Effect..ctor(GraphicsDevice graphicsDevice, Byte[] effectCode)       at Microsoft.Xna.Framework.Graphics.BasicEffect..ctor(GraphicsDevice device)       at Balder.Rendering.Xna.GeometryDetailLevel..ctor() in J:\CS_WPF\SDKs\Balder\balder-4a3f48101a60\Balder_4a3f48101a60\Source\Balder\Rendering\Xna\GeometryDetailLevel.cs:line 72       at Balder.Rendering.Xna.GeometryContext.GetDetailLevel(DetailLevel level) in J:\CS_WPF\SDKs\Balder\balder-4a3f48101a60\Balder_4a3f48101a60\Source\Balder\Rendering\Xna\GeometryContext.cs:line 56       at Balder.Objects.Geometries.Geometry.InitializeProperties() in J:\CS_WPF\SDKs\Balder\balder-4a3f48101a60\Balder_4a3f48101a60\Source\Balder\Objects\Geometries\Geometry.cs:line 65       at Balder.Objects.Geometries.Geometry..ctor(IGeometryContext geometryContext) in J:\CS_WPF\SDKs\Balder\balder-4a3f48101a60\Balder_4a3f48101a60\Source\Balder\Objects\Geometries\Geometry.cs:line 48       at Balder.Objects.Geometries.ArbitraryHeightmap..ctor(IGeometryContext geometryContext) in J:\CS_WPF\SDKs\Balder\balder-4a3f48101a60\Balder_4a3f48101a60\Source\Balder\Objects\Geometries\ArbitraryHeightmap.cs:line 65       at Balder.Objects.Geometries.Heightmap..ctor(IGeometryContext geometryContext) in J:\CS_WPF\SDKs\Balder\balder-4a3f48101a60\Balder_4a3f48101a60\Source\Balder\Objects\Geometries\Heightmap.cs:line 49       at Balder.Objects.Geometries.Heightmap..ctor() in J:\CS_WPF\SDKs\Balder\balder-4a3f48101a60\Balder_4a3f48101a60\Source\Balder\Objects\Geometries\Heightmap.cs:line 41       at MyBalder.MainWindow.Button_Click(Object sender, RoutedEventArgs e) in J:\CS_WPF\WPF\My Experiments\MyBalder\MyBalder\MyBalder\MainWindow.xaml.cs:line 847  InnerException: 

not sure why?

anyway.. i added references to Ninject, XNA framework and ServiceLocator dlls... is there a way i can just reference to Balder.dll and it references to these dlls automatically? sorry if this sounds noob....

Cheers for the WPF release.. :)

Feb 21, 2011 at 10:40 PM

Thanks, sorry to see that it is not working well though... 


You would need to add the references to them - for now at least. 

There is a way of linking assemblies together in one big assembly containing them all. But I've chosen not to go down that route. 



How did you add the Heightmap?  Did you do it through Xaml or do you do it in the .cs file for the Mainpage?   I haven't tested doing it programatically.

Feb 22, 2011 at 2:39 AM

i created the heightmap in the code behind.... 

Feb 22, 2011 at 11:00 AM

Ok. Is it possible for you to try it out in Xaml instead ? 

Feb 23, 2011 at 8:41 AM

Hi, i have a problem creating ByteArray from WPF's WriteableBitmap

in Silverlight you can use the Codeplex's WriteableBitmapEx project to get the ByteArray from the writeablebitmap...

in WPF, i tried writing my own extension method to get the ByteArray() like this

        public static byte[] ToByteArray(this WriteableBitmap bmp)

            // Calculate stride of source
            int stride = bmp.PixelWidth * (bmp.Format.BitsPerPixel / 8);

            // Create data array to hold source pixel data
            byte[] data = new byte[stride * bmp.PixelHeight];

            // Copy source image pixels to the data array
            bmp.CopyPixels(data, stride, 0);

            return data;

however, when i use this to pass into ImageContext.SetFrame() method, i get an ArgumentException: The size of the data passed in is too large or too small for this resource.

i'm not sure if i wrote the extension method wrongly? please advice... thanks

May 13, 2011 at 4:07 PM

would like to know if there are still any plans for WPF support?

May 20, 2011 at 10:24 PM

There is, but time has been the biggest challenge. The focus has been on the Silverlight 4 and 5 support, but this is about to change and other platforms - such as WPF will get more love soon.

Jul 1, 2011 at 5:12 AM

is it soon yet? :)

Jul 10, 2011 at 12:56 PM

Getting there slowly..    Have been working intensively the last couple of weeks with a major refactoring. During this, the XNA rendering, which is part of the WPF support has gotten most of the attention - and now it is at a level where it should be. 

I will be away for 3 weeks starting tomorrow, but in August the focus is to bring all the platforms back online - not only SL4/5.