How to place an image in a control template?

First, thank you for your time.

I need to place numerous Image controls on an InkCanvas. All of them need to animate when certain code conditions are met. After numerous attempts my ControlTemplate is still not right.

<ControlTemplate x:Key="AnimatedImage" TargetType="{x:Type Image}">
        <Image Name="image" 
               Source="{TemplateBinding Filename}"
               Width="{TemplateBinding Width}"
               Height="{TemplateBinding Height}"

                <VisualStateGroup Name="AnimationLocations">

                    <!-- When the image is first loaded move it to the center of the InkCanvas -->
                    <VisualState Name="AnimateToCenterScreen">
                            <DoubleAnimation Storyboard.TargetName="image"
                                             From="{TemplateBinding From}"
                                             To="{TemplateBinding To}"
                                             Duration="{TemplateBinding Duration}" />

                    <!-- Animate the image to an off screen position to effectively hide it.  -->
                    <VisualState Name="AnimateToOffScreen">
                        <!-- To be filled in later.  -->

                    <!-- Animate the image back to the original on screen position.  -->
                    <VisualState Name="AnimateToOnScreen">
                        <!-- To be filled in later.  -->

Open in new window

And my main grid looks like this:
    <InkCanvas Name="inkCanvas" 
                         EditingMode="{Binding EditingMode}" 
                         ResizeEnabled="True" >

            <Image Name="image1" 
                          Template="{StaticResource AnimatedImage}"
                          Source="{Binding Path=Image1}" 
                          VerticalAlignment="Center" >

Open in new window

What is wrong?
Thank you for your time.
Who is Participating?
Sytech SolutionsCommented:
This time with the file!
Sytech SolutionsCommented:
Hi Michael

Please find attached working sample WPF application.  Let me know if you have any questions.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.