返回首页


{S0}简介
我一直在寻找了整整一天的开源解决方案,显示一个简单的缩放和拖动任意内容托管和管理一个ScrollViewer方式。
由于我没有找到一个自由,我决定写我自己一个人。它支持由滑块,以及鼠标滚轮缩放。使用代码
我只会后整个代码。我可能会在未来几周后进一步的评论。
如果您有任何关于使用的问题时,随意张贴。该代码段是足够小,所以,我希望没有作进一步的解释是必要的。
的主要观点是由下面的XAML定义。的内容是可以缩放和拖动是quot; gridquot,控制。

<Window x:Class="ZoomExample.MainWindow"

        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 

        Title="MainWindow" Height="500" Width="500">

    <Window.Resources>

        <ResourceDictionary>

            <ResourceDictionary.MergedDictionaries>

                <ResourceDictionary Source="Resources.xaml"/>

            </ResourceDictionary.MergedDictionaries>

        </ResourceDictionary>

    </Window.Resources>

    <Grid>

        <Grid.ColumnDefinitions>

            <ColumnDefinition Width="Auto"/>

            <ColumnDefinition Width="*"/>

        </Grid.ColumnDefinitions>

        <Slider Grid.Column="0" Orientation="Vertical" 

           HorizontalAlignment="Left" Minimum="1" x:Name="slider"/>

        <ScrollViewer Name="scrollViewer" Grid.Column="1" 

              VerticalScrollBarVisibility="Visible" 

              HorizontalScrollBarVisibility="Visible">

            

            <Grid Name="grid" Width="400" 

              Height="400" RenderTransformOrigin="0.5,0.5">

                <Grid.LayoutTransform>

                    <TransformGroup>

                        <ScaleTransform x:Name="scaleTransform"/>

                    </TransformGroup>

                </Grid.LayoutTransform>

                <Viewbox Grid.Column="0" Grid.Row="0">

                    <ContentPresenter Content="{StaticResource Kompass}"/>

                </Viewbox>

            </Grid>

            

        </ScrollViewer>

    </Grid>

</Window>

缩放和拖动的代码隐藏管理:{C}

回答

评论会员:kgoulding 时间:2012/01/26
感谢的文章,这是一个巨大的帮助。我个人很喜欢您现有的WPF控件添加此功能的方法(而不是一个新的控制Ashley的例子。)

我张贴一些pastebin代码基于本文。 ScrollViewerZoomPanHelper类试图使它有点简单,集中的事情,使滑块和ScrollViewer的要分开。 ZoomSliderHelper使用对数放大,克服限制在小规模大得多的效果比在大型的缩放滑块。







注意:您作为ScaledElement指定的元素,下方应该有一个LayoutTransform一个ScaleTransform直接(如下)BR}
<Grid Width="100" Height="100" HorizontalAlignment="Left" VerticalAlignment="Top" Name="grid">

        <Grid.LayoutTransform>

            <ScaleTransform ScaleX="1" ScaleY="1"></ScaleTransform>

        </Grid.LayoutTransform>

    </Grid>

相依性:

修改01月18日'12
评论会员:Ubloobok 时间:2012/01/26
很简单,但非常有用的例子
评论会员:。Koss87 时间:2012/01/26
CCCCCCCOOOOOOOLLLLL我罚款)))​​)
评论会员:阿什利戴维斯 时间:2012/01/26
您好,

我在WPF的初学者。您的演示项目是一个很大的帮助,我!非常感谢。
努尔
评论会员:萨沙理发 时间:2012/01/26
"由于我没有找到一个自由,我决定写我自己的一个"
你不能看着很难{S1}我写了这篇文章几个月前。
{A5}
萨沙理发
微软的Visual C#MVP 2008年2010Codeproject MVP 2008年2010Your最好的朋友就是你。
我是我最好的朋友。我们有着共同的看法,并未落认为

我的博客:{A6}
评论会员:凯文施通普夫 时间:2012/01/26
。喜凯文

感谢分享您的工作{S2}

,但我could'nt下载的zip文件。我猜想是空的空间中的名称:ZoomPanel演示Project.zipnbsp; {S3}

关于

sinun