ScaleTransform for Image

codematrix picture codematrix · Apr 15, 2010 · Viewed 15.1k times · Source

I am trying to increase the size of the image by 20. So I am using ScaleTransform as shown below.. but the following code doesn't do any scale Tranform.. Any help would be appreciated...

<Grid>
    <Canvas>
    <Canvas Height="50" Width="50" Canvas.Top="10" Canvas.Left="100"
            Visibility="Visible">
        <Image Name="Img" Source="Help.PNG" Canvas.Left="0" Canvas.Top="0">
        </Image>
    </Canvas>
    <Button Canvas.Left="100" Canvas.Top="100" Height="42.5" Name="button3"
            Width="100" Visibility="Visible">
        <Button.Triggers>
            <EventTrigger RoutedEvent="Button.Click">
                <BeginStoryboard>
                    <Storyboard Name="MoveBox">
                        <DoubleAnimation Storyboard.TargetName="Img"
      Storyboard.TargetProperty="(Image.RenderTransform).(ScaleTransform.ScaleX)"
      From="1" To="20" BeginTime="0:0:3.75" Duration="0:0:1.25" />
                        <DoubleAnimation Storyboard.TargetName="Img"
      Storyboard.TargetProperty="(Image.RenderTransform).(ScaleTransform.ScaleY)"
      From="1" To="20" BeginTime="0:0:3.75" Duration="0:0:1.25" />
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger>
        </Button.Triggers>
    </Button>
    </Canvas>
</Grid>

Answer

ChrisF picture ChrisF · Apr 15, 2010

Have you tried setting a <RenderTransform> on the image? Something like this:

    <Image Name="Img" Source="Help.PNG" Canvas.Left="0" Canvas.Top="0">
        <Image.RenderTransform>
            <ScaleTransform x:Name="scale" ScaleX="1" ScaleY="1"
                            CenterX="0.5" CenterY="0.5" />
        </Image.RenderTransform>
    </Image>

This initialises the RenderTransform so that you can refer to it from elsewhere.

I've had to do this with Silverlight.