Change scale down direction in WPF
When using the ScaleTransform, the eleme开发者_运维技巧nt I am scaling is resized:
<BeginStoryboard>
<Storyboard TargetName="ShiftTrain3" TargetProperty="ScaleX">
<DoubleAnimation To="300" Duration="0:0:3"/>
</Storyboard>
</BeginStoryboard>
However, the animation is done from right to the left. I would like to let it resize from right to left. Which property influences this behavior? Is it about the elements alignment?
The image is inside of a canvas panel.
<Image Height="103" HorizontalAlignment="Right" Margin="312,1,0,0" Name="myImage" Source="img/myImage.jpg" Stretch="Fill" VerticalAlignment="Top" Width="400" Canvas.Left="90" Canvas.Top="-1">
this indeed depends on the way the control is aligned. There is no property on the animation itself that allows you to tweak this behaviour.
edit:
your edit states that the image is inside a Canvas. In this case, the image's position is set on its top-left corner and is relative to the top-left corner of the canvas. It is either set by the Canvas.Top and Canvas.Left properties or by the image's margin, or a combination of both.
in any case, this positioning method implies that the Alignment property is ignored by WPF.
so if you want you image to resize from right to left or left to right, you have to position it relatively by putting it inside an other type of control like a Grid or a StackPanel or a DockPanel.
the only other option would be to change the relative X and Y coordinates (or the margins, or both) of the image in accordance with the scale, but this is by no means easy.
edit2: WRONG WRONG WRONG!
I must've hit my head or something, I'm babling nonsense here. There IS a property that you can use on your ScaleTransform:
http://msdn.microsoft.com/fr-fr/library/system.windows.media.scaletransform.centerx.aspx
must be tired -_-
Did you try setting the RenderTransformOrigin of the control? Its default is (0,0) try changing it to (1,0)
精彩评论