I want to display a picture in a canevas. The canevas is smaller than the picture and I want the picture to be scaled and centered like in the exemple below.
I can't use Stretch=UniformToFill
because it crop the part of the picture which are not in the frame (the green parts in exemple) and I need to be able to move the picture. (By moving the picture, the user can select the part of the picture he want to keep). It's also why, I can't use renderTransform.
I try to scale and translate my picture programmatically. I have implemented a pinch to zoom based on this post and now I want to use the CompositeTransform item to do my tranformations.
The scale work but not the translation. Whatever is the scale factor set, nothing change.
What I have with a Stretch=none
:
What I want to get programmaticaly :
Here is my code :
double scaleFactor = (CanvasCropPola.ActualHeight) / Math.Min(ImageCropPola.ActualHeight, ImageCropPola.ActualWidth);
double transX = 500; // regardless of this value, the translation don't work
myCompositeTransfrom.ScaleX = scaleFactor; // work
myCompositeTransfrom.ScaleY = scaleFactor; // work
myCompositeTransfrom.TranslateX = transX; // don't work :'(