This project is read-only.

Binding of Physics Sprites

Aug 2, 2012 at 11:41 PM

I've been attempting to modify the existing (simple WP7) sample to use binding to allow the size of the blocks to be specified in the ucMainGame.xaml eg

<local:ucBlock Canvas.Left="410" Canvas.Top="470" Height="30" Width="120"/>

The changes I've made to ucBlock.xaml are pretty simple, basically add a name to the user control and bind the width of the canvas, sprite and rectangle to the width of the user control eg

<UserControl x:Class="Demo.Simple.ucBlock" x:Name="parentControl" ...>

<Canvas x:Name="LayoutRoot" Width="{Binding Path=Width, ElementName=parentControl}" >
        <ph:PhysicsSprite x:Name="cnvBlock" Width="{Binding Path=Width, ElementName=parentControl}">
            <Rectangle Stroke="Black" Width="{Binding Path=Width, ElementName=parentControl}">

This works for the drawing of the rectangle however the width of the PhysicsSprite is NaN. If I specify a Fallback value in the binding that is used, so it seems like the binding is being run. Is there something I'm missing here?

I can alter the Loading event handling code of PhysicsSprite to detect the NaN and walk the element tree to get the width I require, but I don't see why that should be necessary

Aug 3, 2012 at 12:59 PM

Binding is not something that I tested or implemented very well in this release.

In general, I don't think the overhead incurred with data binding is a good thing to introduce in a physics game for performance reasons. (although in your case, it should only introduce overhead at load time which isn't a big deal. Where it would get noticeable is if you started to bind Postion data on each update).