放大画布而不修改特定子控件的大小 [英] Zooming into a Canvas without modifying the size of specific child controls

查看:32
本文介绍了放大画布而不修改特定子控件的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我意识到我在这里冒险超出了 Canvas 的预期用途,并且可能不得不想出一个更手动的解决方案.但是,由于在 WPF 方面没有过多的经验,我希望可能有一些解决方案可以让我继续使用 Canvas 控件及其免费提供的功能.

So I realize that I am venturing outside of the intended use of a Canvas here and will likely have to come up with a more manual solution. However, not being overly experienced in WPF I was hoping that there may be some solution which would allow me to continue using a Canvas control and the features it gives you for free.

该问题围绕用于放大和缩小图像的 Canvas 以及属于 Canvas 的一些子控件展开.这些子控件将放置在图像上的不同位置,因此,Canvas 工作得很好,因为它可以在我放大或缩小时为我处理所有布局/定位.

The issue revolves around a Canvas which is used to zoom in and out of an image and some number of child controls that belong to the Canvas. These child controls are to be placed at various positions on the image and, as such, the Canvas works nicely in that it handles all of the layout/positioning for me as I zoom in or out.

然而,一个缺点是当我放大图像时,Canvas 会放大这些子控件,导致它们变得太大而无法在实践中使用.我正在寻找一种解决方案,它允许我放大属于画布的图像,而无需放大子控件的大小,最好为我处理布局.

However, one drawback is that the Canvas scales these child controls up as I zoom into the image, causing them to become too large to be usable in practice. What I am looking for is a solution that allows me to zoom into an image that belongs to a canvas without also zooming up the size of the child controls, preferably handling the layout for me.

我曾尝试随着缩放系数的增加或减少来修改这些子控件的宽度和高度,但有一点延迟,而且看起来有点生涩".

I have tried modifying the width and height of these child controls as the zoom factor increases or decreases, but there is a slight lag time and it all looks a bit 'jerky'.

如果归根结底,我将自己完成所有缩放/平移/布局,但我想我会先询问以确保我没有遗漏任何可以让我告诉画布不要的东西缩放某些控件的大小.提前致谢.

If it comes down to it I will simply do all of the zooming/panning/layout myself, but I thought I would ask first just to make sure that I am not missing anything that would allow me to tell the Canvas to not scale the size of certain controls. Thanks in advance.

推荐答案

你可以将孩子的 RenderTransform 绑定到 Canvas 的逆变换,见我对 这个关于轮换的类似问题.

You can bind the children's RenderTransform to the inverse of the Canvas' transform, see my answer to this similar question on rotation.

这篇关于放大画布而不修改特定子控件的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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