I am trying to implement an InkCanvas that has an image loaded onto it. I need to be able to zoom and scroll around that image and make markings to the image.
When I tried to bind the ScaleTransform of the image to a Slider, the image will zoom, but the ink won't.
<Image Name="ImageWork" HorizontalAlignment="Center">
<Image.LayoutTransform>
<ScaleTransform ScaleX="{Binding ElementName=ZoomSlider,Path=Value}" ScaleY="{Binding ElementName=ZoomSlider,Path=Value}" />
</Image.LayoutTransform>
</Image>
</InkCanvas>
</ScrollViewer>
<Slider DockPanel.Dock="Top" Name="ZoomSlider" Value="1" Minimum="0.3" Maximum="3" Height="20" ValueChanged="ZoomSlider_ValueChanged"/>
I tried to change the scale of the Ink itself, but it's not staying in the same place relatively, or zooming across the same anchor point:
private void ZoomSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
if (e.OldValue > 0d)
{
double factor = e.NewValue / e.OldValue;
Matrix scaleMat = new Matrix();
scaleMat.ScaleAt(factor, factor, InkCanvasOnImage.ActualWidth / 2, InkCanvasOnImage.ActualHeight / 2);
InkCanvasOnImage.Strokes.Transform(scaleMat, false);
}
}
How do I get my image and ink strokes to play nicely together?