Canvas和ScrollViewer的缩放问题 [英] Zoom problems of Canvas and ScrollViewer

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

问题描述

大家好,

我正在使用WPF开发图表应用,在实现缩放功能时遇到了一些问题,详情如下:

我将要缩放的所有元素放在一个名为ZoomCanvas的画布中,该画布本身在另一个名为RootCanvas的画布中,图表Axis的标题也都在RootCanvas中.然后,将RootCanvas放入ScrollViewer中,如下所示:

< ScrollViewer Horizo​​ntalScrollBarVisibility ="自动" VerticalScrollBarVisibility =自动">
< Canvas名称="RootCanvas"高度="600".宽度="800"

< Canvas Name ="ZoomCanvas";高度="480".宽度="680". >
< Canvas.RenderTransform>
< ScaleTransform x:Name =" m_canvasTransform"/>
<//Canvas.RenderTransform><><>

< TextBlock/> ...< Line/>

</Canvas>

</ScrollViewer>

我要实现的是仅缩放ZoomCanvas,而不影响任何其他元素.从用户的角度来看,ZoomCanvas的渲染大小是固定的.我使用RenderTransform缩放ZoomCanvas,它可以工作,但是内容将呈现在画布原始大小之外.实际上,ZoomCanvas的高度和宽度没有改变.如何在缩放画布的同时保持其原始大小?

第二个问题是有关的.由于RootCanvas的大小未更改,因此不会通知父ScrollViewer自动启用滚动条.我应该在代码中手动计算偏移量并增加RootCanvas的大小吗?还是有更好的或标准的方法来实现这一目标?

任何评论或建议,我们将不胜感激.

解决方案

您是否要因为以下原因而更新ZoomCanvas的尺寸:它的变形?如果是这样,请在Canvas.LayoutTransform而不是RenderTransform上设置ScaleTransform-


Hi all,

I'm developing a chart app using WPF, I met some problems during implementing zoom functionality, here is the details:

I put all elements I want to zoom in a canvas called ZoomCanvas, which itself is in another Canvas called RootCanvas, the chart Axis, titles are all in RootCanvas, too. Then I put RootCanvas in a ScrollViewer, something like this:

 <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
   <Canvas  Name="RootCanvas" Height="600" Width="800">

     <Canvas  Name="ZoomCanvas" Height="480" Width="680" >
       <Canvas.RenderTransform>
         <ScaleTransform x:Name="m_canvasTransform"/>
       </Canvas.RenderTransform>
     </Canvas>

     <TextBlock/>...    <Line/>

   </Canvas>

 </ScrollViewer>

What I want to achieve is to only zoom ZoomCanvas, without affect any other elements. From user's point of view, the render size of ZoomCanvas is fixed. I use RenderTransform to scale ZoomCanvas, it works, but the content will be rendered outside of the canvas original size. Actually the height and width of ZoomCanvas are not changed. How can I scale the canvas while keep it rendered in original size?

The second problem is related. Since RootCanvas's size are not changed, the parent ScrollViewer doesn't get notified to enable the scrollbar automatically. Should I manualy in the code compute the offset and increase the size of RootCanvas? Or is there any better or standard way to achieve this?

Any comment or suggestion will be highly appreciate, thanks in advance.

解决方案

Do you want dimensions of ZoomCanvas to update because of its Transform? If so, set ScaleTransform on Canvas.LayoutTransform instead of RenderTransform - http://msdn2.microsoft.com/en-us/library/system.windows.frameworkelement.layouttransform.aspx 

If you don't want dimensions of ZoomCanvas to change and want render within bounds then use RenderTransform and set Canvas.ClipToBounds="true".


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

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