I am trying to do two things in my application.
Able to do with RenderTransform
. but need to achieve in LayoutTransform
to enable Scrollviewer
.
working.
<Image.RenderTransform>
<ScaleTransform ScaleX="{Binding ScaleX}" ScaleY="{Binding ScaleY}" />
</Image.RenderTransform>
Not Working
<Image.LayoutTransform>
<ScaleTransform ScaleX="{Binding ScaleX}" ScaleY="{Binding ScaleY}" />
</Image.LayoutTransform>
works with both ScaleTransform
and RenderTransform
but need it with ScaleTransform
to obtain ScrollViewer
Problem is in ScaleTransform
with LayoutTransform
<Image.LayoutTransform>
<TransformGroup>
<ScaleTransform ScaleX="{Binding ScaleX}" ScaleY="{Binding ScaleY}" />
<RotateTransform Angle="{Binding RotateAngle}"/>
</TransformGroup>
</Image.LayoutTransform>
Not able too achieve both ScaleTransform
and RotateTransform
with ScrollViewer
I have tried with Canvas
<Canvas.LayoutTransform>
<TransformGroup>
<ScaleTransform ScaleX="{Binding ScaleX}" ScaleY="{Binding ScaleY}" />
<RotateTransform Angle="{Binding RotateAngle}"/>
</TransformGroup>
</Canvas.LayoutTransform>
Different behavior of rotate but able to achieve both functionality working but ScrollViewer
not scrolling.
-
Tried doing the same with ViewBox
rotate works with ScrollViewer Zoom not working.
Full Code below
<ScrollViewer>
<Viewbox RenderTransformOrigin="0.5,0.5" Height="Auto" Width="Auto" ScrollViewer.CanContentScroll="True">
<Viewbox.LayoutTransform>
<TransformGroup>
<ScaleTransform ScaleX="{Binding ScaleX}" ScaleY="{Binding ScaleY}" />
<RotateTransform Angle="{Binding RotateAngle}"/>
</TransformGroup>
</Viewbox.LayoutTransform>
<Image RenderTransformOrigin="0.5,0.5" >
<Image.Source>
<BitmapImage UriSource="{Binding ImagePath}" ScrollViewer.CanContentScroll="True"></BitmapImage>
</Image.Source>
</Image>
</Viewbox>
</ScrollViewer>
Anyone can help me with suggestions.
Worked solution for me suggested by 'GazTheDestroyer'
<Image RenderTransformOrigin="0.5,0.5" Stretch="None" >
<Image.LayoutTransform>
<TransformGroup>
<ScaleTransform ScaleX="{Binding ScaleX}" ScaleY="{Binding ScaleY}" />
<RotateTransform Angle="{Binding RotateAngle}"/>
</TransformGroup>
</Image.LayoutTransform>
<Image.Source>
<BitmapImage UriSource="{Binding ImagePath}" ScrollViewer.CanContentScroll="True"></BitmapImage>
</Image.Source>
</Image>
Try adding Stretch="None"
to your Image
tag, or failing that supply an explicit height and width.
In certain panels WPF will automatically stretch the image to the available space in the panel, which will make your scale transform redundant when it's part of the layout process.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With