CodePaste Logo
New Snippet New Snippet Recent Snippets Recent Snippets My Snippets My Snippets My Favorites Favorites Web Code Search Snippets Search
Sign inor Register
Language: C#

Animate Delete Item with Opacity

170 Views   
ObservableCollection<string> m_Data;
public MainPage()
{
    InitializeComponent();
    m_Data = new ObservableCollection<string>
    {
        "One", "Two", "Three", "Four"
    };
    MyListBox.ItemsSource = m_Data;
}
 
private void MyListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    var _Item = MyListBox.SelectedItem as string;
    if (string.IsNullOrWhiteSpace(_Item))
        return;
    var _Cont = MyListBox.ItemContainerGenerator.ContainerFromItem(_Item) as ListBoxItem;
 
    var _Story = new Storyboard();
    var _Animation = new DoubleAnimation
    {
        To = 0, Duration = TimeSpan.FromSeconds(.5)
    };
    _Story.Children.Add(_Animation);
    Storyboard.SetTarget(_Animation, _Cont);
    Storyboard.SetTargetProperty(_Animation, new PropertyPath(ListBoxItem.OpacityProperty));
 
    _Animation.Completed += (s, e3) => { m_Data.Remove(_Item); };
 
    _Story.Begin();
 
}
by Jerry Nixon
  January 19, 2012 @ 8:53am
Tags:

Add a comment


Report Abuse
brought to you by:
West Wind Techologies