locked
Creating animations dynamicly RRS feed

  • Question

  • Servus!

    I'm trying to create a small image-gallery as my first silverlight project. I'm creating the "thumbnail-objects" (Canvases with image, rectangle and text) dynamically through C#, which works fine. Now I would like every "thumbnail-object" to have an animation when the mouse hovers over it. AFAIK a storyboard has to have a targetname associated to it. I tried just to assign a name to my objects (like myRectangle.Name = "myName";) but it looks like names can only be assigned in XAML.. I get an error-message saying that the prpoerty is read-only.

    1. Is there any work-around to assign a dynamically created object like a rectangle a name?

    Or

    2. Is there anyway to add an animation to a dynamically created object without needing to assign it to a literal property-name?
     

    Thanks for your help!

     

    Wednesday, January 23, 2008 6:19 PM

Answers

  • hi,

     you can set the name as follows:

    Rectangle rt = new Rectangle();

    rt.SetValue<string>(DependencyObject.NameProperty, "test");

    Debug.WriteLine(rt.Name);

    Wednesday, January 23, 2008 6:33 PM

All replies

  • hi,

     you can set the name as follows:

    Rectangle rt = new Rectangle();

    rt.SetValue<string>(DependencyObject.NameProperty, "test");

    Debug.WriteLine(rt.Name);

    Wednesday, January 23, 2008 6:33 PM
  • Thanks Mario!

    I'm thinking if using user-controls and just hard-coding the name of the elements in XAML for each thumbnail object would be a better approach. I have no idea how encapsulated user-controls are, so I'm eager to find out! Ideally, I would be able to create a bunch of the user-controls dynamically and they would already be animated.

    Gruss nach Linz! 

    Wednesday, January 23, 2008 6:53 PM
  • you can also create storyboards dynamically, even from xaml if you wish. there are plenty of possibilities ...

    Wednesday, January 23, 2008 6:59 PM