This project is read-only.

Problem with dynamally adding a usercontrol

Oct 26, 2012 at 2:17 AM
Edited Oct 26, 2012 at 2:23 AM

I have a user control named bar similar to 

<Canvas x:Name="LayoutRoot">
<ph:PhysicsSprite x:Name="sprite" Canvas.Left="0" Canvas.Top="0" Width="100" Height="10" Margin="0" ShapeType="Polygon">
<Path x:Name="path" Fill="White" Stroke="White" StrokeThickness="2" Canvas.Left="0" Canvas.Top="0" UseLayoutRounding="False" />
public Bar(Geometry pathGeometry) {
            path.Data = pathGeometry;
//sprite.Width = path.Width;
//sprite.Height = path.Height;

I am trying to create this user control dynamically and add it to the gamecanvas,
LineGeometry lg = new LineGeometry { StartPoint = startPoint.Position EndPoint = endPoint.Position, };
Bar b = new Bar(lg); 
cnvGame.AddPhysicsUserControl(b, startPoint.Position.X, startPoint.Position.Y);
Problem here is that physics objects is placed at startPosition, but the line is being drawn at a totally different place. Almost @ startPosition + startPosition. I have tried replacing Path with line, ellipse, etc, nothing seems to work. Uncommenting setting the sprite.height and sprite.width in usercontrol hangs the app, but the line is drawn in expected place. Am I missing something here?
Oct 29, 2012 at 4:57 PM

This doesn't answer your question but I noticed something very similar too.  I added a bunch of normal objects to a PhysicsCanvas, and the ones I added as PhysicsSprites appeared in slightly different places.  This might be relevant to your issue.