im very new to storyboards and animations.
While their setup concept is fairly straightforward, i've been struggling trying to find an efficient way to destroy them to preserve memory in my specific scenario.
Basically i have a listview with several items (list view is dinamically populated by a database) when clicking a button i would like for the listview item to perform a color animation to a specific argb color, since the number of items is dinamically populated, it can have tens or hundreds of items.
To make this process more efficient memory wise and cpu wise, i would like to create animations on the fly, rather than have unnecessary animations per each item, everything works fine except i feel like i need to dispose them to release unnecessary cpu and memory usage which i have no idea on how to do.
Below you can find the code for the button click event which performs the entire operation
employees_data_model.selected_employee_contact.DeleteEmployee = employees_data_model.selected_employee_contact.DeleteEmployee == false; var _Container = Employees_List_View.ContainerFromItem(Employees_List_View.SelectedItem); var GridItem = FindMyChildByName(_Container, "GridItem") as Grid;
if (GridItem.Background == null)
GridItem.Background = new SolidColorBrush(ColorHelper.FromArgb(0, 0, 0, 0));
if (GridItemColorAnimation != null)
{
GridItemAnimationStoryBoard.Stop();
//Here i would like to dispose both GridItemColorAnimation and GridItemAnimationStoryBoard and create new instances below that target different item
}
GridItemColorAnimation = new ColorAnimation();
GridItemAnimationStoryBoard = new Storyboard();
var duration = new Duration(TimeSpan.FromMilliseconds(employees_data_model.selected_employee_contact.DeleteEmployee == true ? 300 : 1000));
GridItemColorAnimation.Duration = duration;
GridItemColorAnimation.EnableDependentAnimation = true;
Storyboard.SetTarget(GridItemColorAnimation, GridItem.Background);
Storyboard.SetTargetProperty(GridItemColorAnimation, "Color");
Storyboard.SetTargetName(GridItemColorAnimation, "GridItem.Background");
GridItemAnimationStoryBoard.Children.Add(GridItemColorAnimation);
GridItemAnimationStoryBoard.Duration = duration;
GridItemColorAnimation.To = employees_data_model.selected_employee_contact.DeleteEmployee == true ? ColorHelper.FromArgb(150, 255, 100, 100) : ColorHelper.FromArgb(0, 0, 0, 0);
GridItemAnimationStoryBoard.Begin();
Thank you very much in advance for all your input.
EDIT: Ok guys thank you very much for your help, its a shame we cannot release them in any way, what im doing is simply using the .Stop() function per each storyboard and releasing them from the list of storyboards with list.clear(), hopefully it will be enough and the GC will collect them automatically, if i find out that i still have to call the garbage collector in the end, so be it, hopefully itll be enough.
Thanks again for all of your help!