Beth

Beth

  • NA
  • 1
  • 0

Problems trying to animate dynamically created rectangles

Feb 20 2009 9:49 PM

Hi everyone,

I have come across a very unusual problem trying to animate dynamically created rectangles in my VB.NET 3.5/WPF project.  I create a series of rectangles based on the number of columns and rows a user inputs.  That is no problem, they are all created just fine.  I then set each rectangle the event handler  for MouseLeftButtonDown:

AddHandler rec.MouseLeftButtonDown, AddressOf Control_MouseLeftButtonDown

Again, that works fine, when I click on a rectangle that event is fired and I can pull the name of the rectangle selected.  But when I add animation to it, the rectangle doesn't animate, the entire form animates!  if I maximize the form, it doesn't run the animation on the form, but if it is free floating, the form actually runs the animation...not the rectangle.  But, as I said, when I check the name of the object (sender)...it comes back with the name of the rectangle...not the form, so sender is being seen as the rectangle and not the form.

Any ideas as to why this happens?

My code is this:

Private Sub Control_MouseLeftButtonDown(ByVal sender As Object, ByVal e As System.Windows.Input.MouseButtonEventArgs)

Dim strName As String

strName = sender.Name

Dim widthAnimation As New DoubleAnimation

widthAnimation.From = 0

widthAnimation.To = 50

widthAnimation.Duration = TimeSpan.FromSeconds(2)

Dim heightAnimation As New DoubleAnimation

heightAnimation.From = 0

heightAnimation.To = 50

heightAnimation.Duration = TimeSpan.FromSeconds(2)

sender.fill = New SolidColorBrush(Colors.Green)

BeginAnimation(sender.WidthProperty, widthAnimation)

BeginAnimation(sender.HeightProperty, heightAnimation)


Answers (1)