WPF. How to show only part of big canvas?

霸气de小男生 提交于 2019-12-05 04:27:42

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!