Zoom problems of Canvas and ScrollViewer

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.

[1736 byte] By [Eilleen] at [2007-12-27]
# 1

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

DennisCheng-MSFT at 2007-9-5 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...

Visual Studio Orcas

Site Classified