PhysicsMagnetBehavior not applied to dynamic objects

Sep 10, 2011 at 11:46 PM

Tribe,

The PhysicsMagnetBehavior is not being applied to the physics object in the below code. Any idea how?

Other objects declared statically in the XAML have magnetism applied successfully. Just not dynamically added objects.

Thanks,

AM

private void InjectBall(){
    counter++;
    PhysicsControllerMain physics = LayoutRoot.GetValue(PhysicsControllerMain.PhysicsControllerProperty) as PhysicsControllerMain;
    Ellipse el = new Ellipse();
    el.Name = "EL" + DateTime.Now.Ticks.ToString();
    el.Fill = new SolidColorBrush(Colors.Red);
    el.Width = counter % 100;
    el.Height = counter % 100;

    el.SetValue(Canvas.ZIndexProperty, 1);
    el.SetValue(Canvas.LeftProperty, (double)(300 - DateTime.Now.Second));
    el.SetValue(Canvas.TopProperty, (double)(DateTime.Now.Second + 200));
    this.LayoutRoot.Children.Add(el);

    PhysicsObjectBehavior physicsBehavior = new PhysicsObjectBehavior();
    physicsBehavior.RestitutionCoefficient = .5;

    PhysicsMagnetBehavior magneticBehavior = new PhysicsMagnetBehavior();
    magneticBehavior.Magnetism = 0.0001 * (counter % 100);
    magneticBehavior.FallOff = 0.1;
    magneticBehavior.MaxDistance = 500;

    System.Windows.Interactivity.Interaction.GetBehaviors(el).Add(physicsBehavior);
    System.Windows.Interactivity.Interaction.GetBehaviors(el).Add(magneticBehavior);

    physics.AddPhysicsBody(el.GetValue(PhysicsObjectMain.PhysicsObjectProperty) as PhysicsObjectMain);

}