Programmatically added ellipses always get an error

Jul 29, 2010 at 12:30 PM

Hi,

in my previous discussion http://physicshelper.codeplex.com/Thread/View.aspx?ThreadId=221686 I explained my HelloWorld example. I just made and application that creates ellipses dinamically in order to play.

The problem I have is this:

  1. I have two usercontrols a ball and a square.
  2. Whenever I press the button a new instance of these two controls is programmatically added to the main canvas.
    Here is the code for the ball.xaml:
    	<Canvas x:Name="LayoutRoot">
    		<Ellipse Fill="#FF33D01E" Stroke="Black" Height="30" Width="30">
    			<i:Interaction.Behaviors>
    				<pb:PhysicsObjectBehavior/>
    			</i:Interaction.Behaviors>
    		</Ellipse>
    	</Canvas>
    and here the square:
    	<Canvas x:Name="LayoutRoot" Width="25" Height="25">
    		<Rectangle Fill="#EAF71919" Height="25" Stroke="Black" Width="25">
    			<i:Interaction.Behaviors>
    				<pb:PhysicsObjectBehavior/>
    			</i:Interaction.Behaviors>
    		</Rectangle>
    	</Canvas>
    
  3. I RECEIVE AN ERROR WHENEVER I TRY TO ADD THE ELLIPSE BUT NOT THE SQUARE!! : Could not determine the outline of UIElement sprite_2. Could not find a point within its boundaries

The only solution I found for this is very complex and maybe I'm missing something and besides that, why is this happening only with ellipses and not rectangles?? Is a know issue?

First of all, if you try to put an instance of ball in the stage you will receive the same message. Secondly, if you try to name the inner ellipse it will raise again the same error.
But if you do both things then it will work!! Why is this happening? Can anyone shed some light on this?

Many thanks!

Aug 26, 2010 at 2:50 AM

The calculations only work with a fixed size canvas, by default SL apps are running at 100% size in your aspx or html testpage, this messes up the absolute size.

Aug 26, 2010 at 8:27 AM

Hi Joris7dries, I've applied a determined size to my canvas but no effect on the balls behaviour...