0

Hi. I am trying to perform a TranslateTransform on an Image using this code:

double to;
int increment = 2;

TranslateTransform tt = new TranslateTransform();
background.RenderTransform = tt;

to = Canvas.GetTop(background) + increment;
DoubleAnimation da = new DoubleAnimation(to, TimeSpan.FromSeconds(0));
Canvas.SetTop(background, to);
tt.BeginAnimation(TranslateTransform.YProperty, da);

This works when the Image exists in a Window:

<Window x:Class="trpgwpf1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" ResizeMode="CanMinimize" KeyDown="WindowKeyDown">
    <Canvas Name="canvas">
        <Image Name="background" Stretch="UniformToFill" Source="Images\test.png" />
    </Canvas>
</Window>

But nothing happens when I try to transform an Image on a Page:

<Page x:Class="trpgwpf1.Page1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Page1">
    <Canvas Name="canvas">
        <Image Name="background" Stretch="UniformToFill" Source="Images\test.png" />
    </Canvas>
</Page>

Does anyone know why? I can't find a reference to anything like this anywhere.

2
Contributors
2
Replies
13
Views
3 Years
Discussion Span
Last Post by catpoints
0

I think you want to use the transform on the backgrounds' Canvas.TopProperty.

Like this:

            double To = -1000;
            double From = (double)Background.GetValue(Canvas.TopProperty);

            DoubleAnimation da = new DoubleAnimation(From, To, TimeSpan.FromMilliseconds(10));

            Background.BeginAnimation(Canvas.TopProperty, da);

The problem, i think you will run into, however, is that you have the UniformToFill set and so your image might stretch/.

Mark A. Malo

0

Thanks, unfortunately I'm still not seeing the animation with your code.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.