I would like to use StoryBoard to show an image with an animation of the projection of the plane when I press the button.
This works when I try to use it in only one instance.
But on my silverlight page (windows phone 7) I use a data template to repeat it from a collection of objects.
And here it does not work.
Here is the .xaml data template:
<DataTemplate x:Name="MyDt"> <Button Tag="{Binding iId}" BorderThickness="0" Click="buttonClick" Width="456" Style="{StaticResource ButtonStyle}"> <Image x:Name="MyImg" Source="Images/image.png" Visibility="Collapsed"> <Image.Projection> <PlaneProjection/> </Image.Projection> </Image> </Button> </DataTemplate>
Here is the .xaml storyboard (in the phone page resources):
<Storyboard x:Name="storyboardShowImage"> <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationY)" Storyboard.TargetName=""> <EasingDoubleKeyFrame KeyTime="0" Value="90"/> <EasingDoubleKeyFrame KeyTime="00:00:01" Value="0"/> </DoubleAnimationUsingKeyFrames> </Storyboard>
Here is the button click .cs button:
private void buttonClick(object sender, RoutedEventArgs e) { Image img; img = GetChildImage((DependencyObject)sender, "MyImg"); ((DoubleAnimationUsingKeyFrames)storyboardShowImage.Children[0]).SetValue(Storyboard.TargetNameProperty, img.Name); storyboardShowImage.Begin(); }
But I get the error:
Cannot resolve TargetName MyImg.
I think this is because there are several Image objects with x: Name "MyImg", but I do not know how to set the storyboard goal to the correct image in my data template.
source share