Language: C#
Animate Delete Item with Opacity
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(); }
Tags:
Report Abuse
Subscribe
Discuss
News
About
New Snippet
Recent Snippets
My Snippets
Favorites
Web Code
Search
Copy
Line#