Move (zoom and pan) around a large Canvas - wpf

I have a lot of images placed on a canvas (~150 pages converted PDF).
I would like to be able to move around from one region to another of this canvas by animating the movement (zoom and pan).
My animation keys are in a listbox. I have a "play" button to play all.
When I click an animation key, my "camera" automatically moves to the defined location.
It's a kind of "Prezi wall".

This is only half or three quarters of an answer really, but hopefully you can fill in the gaps. You could try using the VisualBrush Class. First you set up the visual that the VisualBrush will paint using your full Canvas:
VisualBrush visualBrush = new VisualBrush();
visualBrush.Visual = yourCanvasElement;
You then paint with the Brush onto, let's say, a Rectangle element:
Rectangle rectangle = new Rectangle();
...
rectangle.Fill = visualBrush;
You can then use the VisualBrush.Viewbox property to move the content about. Now I think that there is some way of zooming in and out, but I can't remember at the moment.
Alternatively, you could use the ViewBox class. You can get your zooming effect by changing the size of the content and the ViewBox and get your panning effect by using a ScrollViewer. There's a post on StackOverflow that demonstrates this, so please take a look at the Zooming To Mouse Point With ScrollView and ViewBox in Wpf post for more help with this method.

Related

WPF InkCanvas Z-Index for strokes

In WPF InkCanvas, ink is rendered on top and strokes don't have z-index property. I have other UIElements like shape, images on InkCanvas and can't bring UIElements to top. Is there any work around for this problem. I have tried
below things.
1) use two different InkCanvas (one for strokes & one for UIElements)
- Can't achieve sandwich effect in this (i.e. UIElement between strokes
Something like this in this circle is UIElement
2) Masking strokes using geometry path and add as UIElement
- If I add strokes as UIElements (using path) then I will loose erase functionality.
The map editor which is part of our game suite uses ink to draw terrain so I have recent experience of this sort of thing.
The way my app works is you select a thing you're drawing ( woods, road, contour etc ) and draw a stroke using ink.
I then process that stroke and obtain a geometry.
I pass that to a viewmodel > itemssource > itemscontrol.
This is then templated into a piece of terrain.
This itemscontrol is below the inkcanvas.
The user can manipulate the z-index of those by moving them up and down in the observablecollection.
I rely on just the order to define z-index.
I also retain the data from each stroke by serialising it.
You're thinking "how about erase?".
To do that I'd have an explicit erase-this-thing mode.
Let them pick a shape and get it's stroke data, add the stroke back to the inkcanvas. Once they finish erasing then use a "save changes" button or something to re-process the stroke(s) and switch back to edit mode.
Since this is a game map editor I'm working on, drawing produces area and line types of terrain but their area/line is defined by a geometry translated from a stroke. ZIndex corresponds to the order of objects in the left panel. The buttons you can see with the chevrons pointing up and down move the order of a

Crop WPF control

I have to crop some control to show only a half of it but the rest should be transparent and clickable so it is not enough to cover the control with something. The result should give a control with only half of the content (for example 50% of top) and the rest should be cropped (not hidden) so some other control below should be visible and not overlapped by cropped part. New control should also scale when window is scaled. How to do this in WPF?
I have finally did the trick using Border around the control and Clip property of this border was set to Multibinging that was generating Rectangle basing on ActualWidth and ActualHeight of my control
Maybe GridSplitter:
http://www.wpf-tutorial.com/panels/gridsplitter/
Can be used to split views horizontally/vertically, and can be responsive.

two questions about rectangle and canvas in silverlight 4

I have a rectangle on canvas. I can already moving this object using with mouse, but I can't find how can I resize it in runtime using mouse too?
And second question, how can I programatically check positions of each objects (e.g rectangles) on the canvas?
Most people use a Thumb. This is an msdn article that shows you how to use a thumb to resize a canvas. The same principles can be applied to your rectangle.
Re-sizing a rectangle using the mouse can be pretty involved. Basically you can listen for mouse-down, mouse-up, and mouse-move events which would allow you to adjust the width and height of it programmatically.
To move a rectangle within the canvas, try the following concept:
double x = Canvas.GetLeft(this.myRectangle);
x += 100;
Canvas.SetLeft(this.myRectangle, x);

How to draw onto a PictureBox image when control resizes?

I am using the pictureBox_Paint event to try and draw an overlay onto the image in a PictureBox.
This is working fine until I resize the PictureBox (set to use SizeMode.Zoom), when I do this the overlay graphic is drawn off position by the margin between the image and the edge of the PictureBox. I guess I need to use the ImageRectangle somehow but this is not public.
I would create a custom usercontrol instead, you would have much more control, and would not be difficult to build.

WPF Clipping Problem

I have a UserControl which has a quadratic Image as a Child. This Image is at the bottom of the UserControl, and half of it is clipped (e.g. the Control's Height is 400, Image's height is 200 and it is set to y=300).
Now, When I rotate the Image, it is still clipped like the way it was first. Like when rotating around 90 degrees, I suddenly have an Image which is only 100px wide.
It seems like the original clipping which was made because of the bounds of the UserControl, are applied forever.
How do I solve this problem? I hope I explained my problem understandable ;)
How are you rotating the image? If you are rotating using a RenderTransform, then WPF does not re-render what was already displayed on the screen - it simply rotates the pixels.
Instead, rotate the image using a LayoutTransform; this forces WPF to re-render the control given the new area it occupies, which should eliminate the clipping you see.
You can also call InvalidateMeasure() after applying render transform.

Resources