Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF. How to show only part of big canvas?

Lets say I have a canvas defined to be 1000x1000 big. Is it possible to only show a 100x100 part of it in a Viewbox(or a rectangel)?

Any help is apreciated.....

like image 448
Erik Z Avatar asked Aug 24 '09 11:08

Erik Z


1 Answers

If you work with Brushes, you might want to take a look at Viewbox and Viewport in WPF

Edit: I just realised that Viewbox and Viewport are used for Brushes This is not really appropiate in your situation. I looked it up, and I think you will like the Clip property on UIElement.

Since Canvas is also a UIElement, you can use the Clip property to simulate a viewport on your Canvas..

Click here for some simple Geometry types

I think you would suffice with a RectangleGeometry

<Canvas>
    <Canvas.Clip>
        <RectangleGeometry Rect="50,50,25,25" />
    </Canvas.Clip>
</Canvas>

Edit #2:

Hehe ok.. if you want your total Canvas displayed, only smaller, perheps you should take a look and LayoutTransform. Then use a ScaleTranform to resize your Canvas ;).

<Canvas>
    <Canvas.LayoutTransform>
        <ScaleTransform CenterX="0" CenterY="0" ScaleX="0.5" ScaleY="0.5" />
    </Canvas.LayoutTransform>
</Canvas>

Tweak the parameters until you receive the desired effect ;)

like image 103
Arcturus Avatar answered Oct 30 '22 00:10

Arcturus