8

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.....

Simon Sarris
  • 62,212
  • 13
  • 141
  • 171
Erik Z
  • 4,660
  • 6
  • 47
  • 74

1 Answers1

7

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 ;)

Arcturus
  • 26,677
  • 10
  • 92
  • 107
  • Viewport is exactly what I want. Unfortunalely there is no such property for the canvas. How can I get around that limitation? – Erik Z Aug 24 '09 at 12:51
  • Hey Erik.. I changed the answer a bit... I think the Clip property will be more appropiate :) – Arcturus Aug 24 '09 at 17:30
  • Thank you! Clip is nearly what I'm searching for. I can clip to show only a part of the canvas.....BUT I want to resize that clipped region fill it's container. Is that possible? – Erik Z Aug 25 '09 at 07:36
  • I must clearify myself. I want the clipped region to fill out the same area as the original canvas does. – Erik Z Aug 25 '09 at 07:37
  • ViewBox (not ViewPort) has nothing to do with brushes, and I think it's exactly what you need. Just put your content inside it and set the appropriate properties – Thomas Levesque Aug 25 '09 at 08:30