Image manipulation and scroll bars in WPF

483 views
Skip to first unread message

Peter O'Hanlon

unread,
Feb 28, 2013, 2:36:11 AM2/28/13
to WPF Disciples
Has anybody played around with DeltaManipulation on an image inside a ScrollViewer in WPF? What I'm trying to do is pan and zoom an image using touch, but when the user changes the pan or zoom, the scrollbars don't change size/position to match?

This is a WPF 4.5 app.

My XAML
    <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
        <Image 
            Source="{Binding PreviewImage}" 
            HorizontalAlignment="Stretch" 
            x:Name="scaleImage" 
            ManipulationDelta="scaleImage_ManipulationDelta_1" 
            ManipulationStarting="scaleImage_ManipulationStarting_1"
            ManipulationCompleted="scaleImage_ManipulationCompleted_1"
            VerticalAlignment="Stretch" 
            IsManipulationEnabled="True"
            RenderTransformOrigin="0.5,0.5" Stretch="Fill" >
            <Image.RenderTransform>
                <MatrixTransform>
                </MatrixTransform>
            </Image.RenderTransform>
        </Image>
    </ScrollViewer>
My code

        private void scaleImage_ManipulationDelta_1(object sender, ManipulationDeltaEventArgs e)
        {
 
            Matrix rectsMatrix = ((MatrixTransform)scaleImage.RenderTransform).Matrix;
            ManipulationDelta manipDelta = e.DeltaManipulation;
            Point rectManipOrigin = rectsMatrix.Transform(new Point(scaleImage.ActualWidth / 2, scaleImage.ActualHeight / 2));
 
            rectsMatrix.ScaleAt(manipDelta.Scale.X, manipDelta.Scale.Y, rectManipOrigin.X, rectManipOrigin.Y);
            rectsMatrix.Translate(manipDelta.Translation.X, manipDelta.Translation.Y);
            ((MatrixTransform)scaleImage.RenderTransform).Matrix = rectsMatrix;// (MatrixTransform)(new MatrixTransform(rectsMatrix).GetAsFrozen());
            e.Handled = true;
 
        }
 
        private void scaleImage_ManipulationStarting_1(object sender, ManipulationStartingEventArgs e)
        {
            e.ManipulationContainer = this;
            e.Handled = true;
        }
--
Peter O'Hanlon

Sacha's Gmail

unread,
Feb 28, 2013, 3:08:01 AM2/28/13
to wpf-di...@googlegroups.com
You can control the scrollviewer yourself have a look at my metro panorama control at codeproject it has that code in it

Sent from my iPhone
--
 
---
You received this message because you are subscribed to the Google Groups "XAML Disciples" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wpf-disciple...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Peter O'Hanlon

unread,
Feb 28, 2013, 3:35:10 AM2/28/13
to wpf-di...@googlegroups.com
Cheers mate. I wondered if I would have to do that.

From: Sacha's Gmail
Sent: 28/02/2013 08:08
To: wpf-di...@googlegroups.com
Subject: Re: [WPF Disciples] Image manipulation and scroll bars in WPF

Sacha's Gmail

unread,
Feb 28, 2013, 4:20:13 AM2/28/13
to wpf-di...@googlegroups.com
Think so

Sent from my iPhone
Reply all
Reply to author
Forward
0 new messages