Adding new objects programatically in Blend 4

Jul 28, 2010 at 9:07 AM


I'm trying to add a new object programmatically but whenever I try I get the following error:

Could not determine the outline of UIElement bola634159077085944453. Could not find a point within its boundaries.

Here is my code on a button click handler:

        Dim b As New Ellipse
        b.Height = 22
        b.Width = 22
        'note that these 2 lines will return nothing!! why?
        Dim p = PhysicsControllerMain.GetPhysicsController(pantalla)
        p = pantalla.GetValue(PhysicsControllerMain.PhysicsControllerProperty)
        'and this will raise the error

  Besides the error informed above I'm unable to get a reference to the PhysicsControllerMain and I have to name it in order to get a reference to it. I followed the example in the home page but it seems not to work.

Just to clarify:

pantalla => is the main canvas
phController => PhysicsControllerMain

I got a PhysicsControllerMain and a PhysicsStaticHolder. I googled for this error with no success. Anyone there that can help me with this? I'm using Blend 4 and targeting Blend 4 too, with the Change Set 55578.






Jul 28, 2010 at 9:09 AM

In the error above please ignore the name of the UIElement in the error message. I just tried naming the object in case it was needed but...

Jul 28, 2010 at 11:35 AM

When you add an object dynamically, you need to make sure that it has been drawn to the screen before boundary detection can work. I usually do this with a short (100 ms or so) Storyboard.

Also check out these other posts

Jul 28, 2010 at 12:20 PM

Hi Andy,

any idea why I cannot get a reference to PhysicsControllerMain?

Jul 28, 2010 at 12:52 PM

I think that what I'm doing here is different from the doll example as I don't really use a physicsControllerMain that's why I can't get a reference to it as it does not exist:

<Canvas x:Name="pantalla" Margin="0" Background="#FFAFA6A6">
		<Path x:Name="tubo" Data="M0.5,0.5 L0.52364284,0.5 L0.60435027,7.3271866 C4.9783115,192.12895 146.30214,340.5 320,340.5 C493.69788,340.5 635.02167,192.12895 639.39563,7.3271866 L639.47638,0.5 L639.5,0.5 L639.5,412.5 L0.5,412.5 z" Fill="#FF7A440E" Stretch="Fill" Stroke="Black" UseLayoutRounding="False" Height="413" Canvas.Top="67" Width="640"/>
		<local:bolaControl x:Name="bola" Height="57" Canvas.Left="311" Canvas.Top="77" Width="57"/>
		<Button Content="Add ball" Height="33" Canvas.Left="480" Canvas.Top="8" Width="99" Click="Button_Click"/>
		<Spritehand_FarseerHelper:PhysicsController x:Name="phController" d:LayoutOverrides="Width, Height" GravityVertical="500" MousePickEnabled="True"/>
		<Spritehand_FarseerHelper:PhysicsStaticHolder d:LayoutOverrides="Width, Height" Body="tubo"/>