开发者

Silverlight zoom area with canvas and scrollview

开发者 https://www.devze.com 2023-02-10 17:34 出处:网络
I have simple canvas with items and i need to add for scro开发者_Go百科ll view as parent for my canvas.

I have simple canvas with items and i need to add for scro开发者_Go百科ll view as parent for my canvas. But i fased with problem that after set

canvas.RenderTransform=new ScaleTransform(){...}

Scroolbars not appears or working not correctly. Will be glad for any information.


The render transform occurs much later in the UI rendering process. It ultimately performs a matrix transform on controls rendering. The scroll viewer will be completely unware of this transform, its scrollbars will be based on the un-transformed size of the original Canvas.

The silverlight toolkit contains a LayoutTransformer control. This control applies a transform to its content as part of the layout process and reports the post-transform size as its desired size.

Consider this:-

    <ScrollViewer Width="200" Height="200" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
        <toolkit:LayoutTransformer>
            <toolkit:LayoutTransformer.LayoutTransform>
                <ScaleTransform ScaleX="2" ScaleY="2" />
            </toolkit:LayoutTransformer.LayoutTransform>
            <Canvas Width="150" Height="150" Background="Aquamarine">
                <Rectangle Fill="Blue" Canvas.Top="10" Canvas.Left="10" Width="30" Height="30" />
            </Canvas>
        </toolkit:LayoutTransformer>
    </ScrollViewer>

Whilst the Canvas has a size (150) smaller than the containing scroll viewer (200), it is scaled so that it would be larger (300). The LayoutTransformer reports its desired size as 300, the post-transform size of the canvas. Hence the ScrollViewer displays scroll bars to accomodate it. Without the benefit of the LayoutTransformer the ScrollViewer would only see the Canvas as having a size 150 despite any applied RenderTransform.

0

精彩评论

暂无评论...
验证码 换一张
取 消