WPF.如何只显示大画布的一部分? [英] WPF. How to show only part of big canvas?

查看:349
本文介绍了WPF.如何只显示大画布的一部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以说我有一个定义为1000x1000大的画布.是否可以在Viewbox(或矩形)中仅显示其100x100的一部分?

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

推荐答案

如果您使用Brushes,则可能需要看一下

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

编辑:我刚刚意识到Viewbox和Viewport用于笔刷 这实际上不适合您的情况.我查了一下,我想您会喜欢剪辑属性.

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.

由于Canvas也是UIElement,因此可以使用Clip属性在Canvas上模拟视口.

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

单击此处获取一些简单的几何类型

我认为您只要使用RectangleGeometry就足够了

I think you would suffice with a RectangleGeometry

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

编辑#2:

呵呵,好吧.如果您希望显示您的总Canvas,只有较小的,垂直的,您应该看一下并 ScaleTranform 调整Canvas的大小; ).

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

这篇关于WPF.如何只显示大画布的一部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆