| Subject: How to stop an animation when an item is about to be deleted? |
| Group: microsoft.public.windows.developer.winfx.sdk,microsoft.public.expression.interactivedesigner |
| Date: 1/10/2007 2:01:21 AM |
| From: Philippe Lavoie [Email Address Protection] |
Hi I have a list which contains items which have some buttons on them. My problem arise when I remove when of those items. I have a set an animation on the mouse enter and mouse leave event, but when I delete the item, the system throw up an error because it was in the middle of animating the object (or it didn't have a chance to start before the object got deleted). My Xaml looks like <ControlTemplate.Resources> <Storyboard x:Key="GrowDefaultButton" > <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="DefaultButtonCanvas" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)"> <SplineDoubleKeyFrame KeyTime="00:00:00.5000000" Value="1.25"/> </DoubleAnimationUsingKeyFrames> <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="DefaultButtonCanvas" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)"> <SplineDoubleKeyFrame KeyTime="00:00:00.5000000" Value="1.25"/> </DoubleAnimationUsingKeyFrames> </Storyboard> <Storyboard x:Key="ShrinkDefaultButton"> <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="DefaultButtonCanvas" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)"> <SplineDoubleKeyFrame KeyTime="00:00:00.5000000" Value="1.0"/> </DoubleAnimationUsingKeyFrames> <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="DefaultButtonCanvas" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)"> <SplineDoubleKeyFrame KeyTime="00:00:00.5000000" Value="1.0"/> </DoubleAnimationUsingKeyFrames> </Storyboard> </ControlTemplate.Resources> .... template removed for brievety <ControlTemplate.Triggers> <EventTrigger RoutedEvent="Mouse.MouseEnter"> <EventTrigger.Actions> <BeginStoryboard Storyboard="{StaticResource GrowDefaultButton}" x:Name="GrowDefaultButtonStoryboard"></BeginStoryboard> </EventTrigger.Actions> </EventTrigger> <EventTrigger RoutedEvent="Mouse.MouseLeave"> <EventTrigger.Actions> <BeginStoryboard Storyboard="{StaticResource ShrinkDefaultButton}" x:Name="ShrinkDefaultButtonStoryboard"></BeginStoryboard> </EventTrigger.Actions> </EventTrigger> <EventTrigger RoutedEvent="FrameworkElement.Unloaded"> <EventTrigger.Actions> <RemoveStoryboard BeginStoryboardName="GrowDefaultButtonStoryboard"/> <RemoveStoryboard BeginStoryboardName="ShrinkDefaultButtonStoryboard"/> </EventTrigger.Actions> </EventTrigger> </ControlTemplate.Triggers> I was hoping against all hopes that the unloaded event would be triggered when I change the source of an list box.ItemsSource or when I simply remove an item inside the collection. In either cases, it seems to fail. But the system just throws an exception stating that GrowDefaultButton doesn't exist. Hopefully, there is a solution. thanks Phil |
| Back |