WPF中心放大问题 [英] Center Zoom in WPF problem

查看:65
本文介绍了WPF中心放大问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在我的应用程序中,我有一个Canvas,其中包含多个拇指&画布.我想从中央放大当您位于特定位置时,可以放大以扩大焦点,该焦点不应像google map一样松动.我正在使用以下代码来实现它:

ScaleTransform scale = new ScaleTransform(1,1,0,0);
scale.CenterX = mousePosition.X;
scale. CenterY = mousePosition.Y; 
scale.ScaleX = zoomFactor;
scale.ScaleY = zoomFactor;

我的问题是滚动查看器无法反映变化的缩放,因此图像的某些部分无法访问

我提到了以下有关通过添加scrollchange事件来更新滚动条位置的线程,仍然没有运气

http:///social.msdn.microsoft.com/Forums/zh-CN/wpf/thread/5202aae5-b2cc-4fc3-aa43-4541fcc856fb

任何帮助将不胜感激.

谢谢
Deepak


Deeps

Hi,

In my application I have a Canvas, which contains multiple thumb & canvases. I want to zoom in from the center & the focus should not loose like google map when you are on a particular location you can zoom in to expand that. I am using following code to achieve it :

ScaleTransform scale = new ScaleTransform(1, 1, 0, 0);
scale.CenterX = mousePosition.X;
scale.CenterY = mousePosition.Y; 
scale.ScaleX = zoomFactor;
scale.ScaleY = zoomFactor;

My problem is the scrollviewer doesnt' reflect the zoom in change, so some part of the image is not accessible in zoom-in mode because of scrollviewer is not getting updated.

I referred to following thread about updating the scrollbar position by adding scrollchange event, still no luck

http://social.msdn.microsoft.com/Forums/en/wpf/thread/5202aae5-b2cc-4fc3-aa43-4541fcc856fb

Any help will be greatly appreciated.

Thanks
Deepak


Deeps

推荐答案



问题可能是画布没有设置尺寸.画布默认情况下无论显示的内容是ActualHeight和ActualWidth 0.因此,您需要一些代码来找出Canvas需要占用多少空间才能显示其所有内容,然后相应地设置Canvas的大小.一旦未缩放的大小不同于0并设置为正确的值,如果将变换用作LayoutTransform,则应该自动计算缩放的大小.

您可以做的是从Canvas派生一个自定义类.并重写ArrangeOverride和MeasureOverride方法,以便从其子控件中找出画布的边界矩形.但是,如果这些孩子也都是画布,那么您在那里也会遇到同样的问题,因为他们不会告诉您他们的孩子占用了多少空间...
Hi,

the problem is probably that the Canvas has no size set. A Canvas has by default the ActualHeight and ActualWidth 0, no matter what it displays. So, you need some code that finds out how much space the Canvas needs to occupy in order to display all its contents, and then sets the size of the canvas accordingly. Once the unzoomed size is different from 0 and set to the correct value, the zoomed size should be calculated automatically if you use your transform as LayoutTransform.

What you could do is to derive a custom class from Canvas and override the ArrangeOverride and MeasureOverride methods in order to find out the bounding rectangle of the canvas from its child controls. However, if those children are canvases, too, you would run into the same problem there, because they wouldn't tell you how much space their children take up...


这篇关于WPF中心放大问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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