WPF 缩放控制

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34422337/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 13:36:07  来源:igfitidea点击:

WPF Zoom control

wpfzoom

提问by lata

How to implement zooming in wpf? Creating an application in which user can upload and draw on the map.On using zoom slider, user is not able to draw on the map. Without zoom slider the user is able to draw. Instead of third party controls, is there any way to implement zooming? I tried implementing it and i can see the slider in xaml but when i run it,the slider disappears

如何在wpf中实现缩放?创建一个应用程序,用户可以在其中上传和在地图上绘图。使用缩放滑块时,用户无法在地图上绘图。没有缩放滑块,用户可以绘制。除了第三方控件,有没有办法实现缩放?我尝试实现它,我可以在 xaml 中看到滑块,但是当我运行它时,滑块消失了

enter image description hereAny ideas are greatly appreciated. Thanks a lot.

在此处输入图像描述任何想法都非常感谢。非常感谢。

     <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="273.333"/>
                                    <ColumnDefinition Width="1026.667"/>
                                </Grid.ColumnDefinitions>

                                <Slider x:Name="uiScaleSlider" ToolTip="Determines the UI scale factor." Value="1" Minimum="0.1" Maximum="4" Margin="67,0,-67,-0.333" Grid.ColumnSpan="2"/>
                                <DockPanel Grid.Column="0" Grid.ColumnSpan="2" LastChildFill="True" Margin="0,0,0,-0.333">
                                    <DockPanel.LayoutTransform>

                                        <ScaleTransform 
        CenterX="0" CenterY="0"
        ScaleX="{Binding ElementName=uiScaleSlider,Path=Value}"
        ScaleY="{Binding ElementName=uiScaleSlider,Path=Value}"
    />
                                    </DockPanel.LayoutTransform>
                                    <Canvas x:Name="drawingCanvas" Margin="0,10,85,33">
                                        <Canvas.Background>
                                            <ImageBrush ImageSource="../Images/canvas.png" AlignmentX="Center" AlignmentY="Center" Stretch="Fill"/>
                                        </Canvas.Background>
                                    </Canvas>
                                </DockPanel>
                            </Grid>
                        </ScrollViewer>
                        <GridSplitter Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Top" ResizeDirection="Rows" />

                    </Grid>

回答by d.moncada

The best way to do this is to use a ViewBox. I've described a similar scenario here: Creating a WPF Window that allows zooming and panning

最好的方法是使用ViewBox. 我在这里描述了一个类似的场景:Creating a WPF Window that allowed zooming and panning