Search code examples
c#windows-phone-8longlistselector

How to animate single item in LongListSelector?


I am trying to animate item removal from LongListSelector. However I have no idea how to pass selected item to StoryBoard.SetTarget. I was so far able to pass whole LongListSelector so when SelectionChanged event is fired everything disappears (I want to animate Opacity from 1 to 0). I have custom template for my list.

My code:

Storyboard s = new Storyboard();

            DoubleAnimation animation = new DoubleAnimation();
            animation.To = 0;
            animation.Duration = new Duration(TimeSpan.FromSeconds(0.70));

            Storyboard.SetTarget(animation, selector);
            Storyboard.SetTargetProperty(animation, new PropertyPath(OpacityProperty));

            s.Children.Add(animation);

            s.Begin();

            s.Completed += s_Completed;

Thanks.


Solution

  • To access items in a LongListSelector you will need to use a VisualTreeHelper which goes through the "children" of the LongListSelector.

    Check out the following link which applies to the ListBox control but works essentially the same for a LongListSelector:

    http://www.geekchamp.com/tips/how-to-access-a-control-placed-inside-listbox-itemtemplate-in-wp7