放大到画布中的所有内容 [英] Zooming into all content of a Canvas
问题描述
我有此XAML:
<Grid x:Name="DrawingGrid" Visibility="Collapsed">
<AppBarButton x:Name="ExitDrawingButton" Icon="Cancel" Click="ExitDrawingButton_Click"></AppBarButton>
<ScrollViewer x:Name="DScrollViewer" ManipulationMode="All" MaxZoomFactor="2.0" MinZoomFactor="1.0" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden" DoubleTapped="DScrollViewer_DoubleTapped" Width="1140" Height="770">
<Canvas x:Name="inkCanvas" Background="Transparent" Width="1140" Height="770">
<StackPanel x:Name="DStackPanel" Orientation="Horizontal" Margin="0,0,0,0">
<Image x:Name="DImage0" HorizontalAlignment="Left" Source="{Binding nextImage}" Width="570" Canvas.ZIndex="0"/>
<Image x:Name="DImage1" HorizontalAlignment="Left" Source="{Binding nextImage}" Width="570" Canvas.ZIndex="0"/>
</StackPanel>
</Canvas>
</ScrollViewer>
</Grid>
我吸取了使用CanvasManager画布
的.cs类,它是工作的罚款。
现在我需要放大的画布
:缩放画布
(油墨)和变焦是什么包含(即的StackPanel
+的图像)在一起。
I am drawing on Canvas
using the CanvasManager.cs class and it is working fine.
Now I need to zoom on the Canvas
: Zoom the Canvas
(the ink) and Zoom what it contains (the StackPanel
+ the Images) together.
在 doubleTapping
中包含画布
我有这种方法的ScrollViewer
:
On doubleTapping
the ScrollViewer
containing the Canvas
I have this method:
private async void DScrollViewer_DoubleTapped(object sender, DoubleTappedRoutedEventArgs e)
{
Point point = e.GetPosition(DScrollViewer);
if (DScrollViewer.ZoomFactor == 1)
{
await Task.Delay(300);
DScrollViewer.ChangeView(point.X, point.Y, 2.0F, false);
}
else
{
await Task.Delay(300);
DScrollViewer.ChangeView(point.X, point.Y, 1.0F, false);
}
}
结果是:只有画布
(其墨)缩放和的StackPanel
和图像的地点,同样的标尺左,完好!
The result is: only the Canvas
(its Ink) is Zooming and the StackPanel
and its Images are left at the place, same scale, intact!
我究竟做错了什么?
推荐答案
您的错误是你指定一个恒定值每个图像的宽度( WIDTH =570
),所以它永远不会放大或缩小,除非你有改变它的宽度编程。
Your mistake is you are assign a constant value for the width of each image (Width="570"
) so that it will never zoomed in or out unless you have change it's width programmatically.
改变图像的宽度最好的办法是绑定变量的值,你可以创建划分画布宽度超过两(canvas.width / 2)转换器并结合各自的宽度图像此转换器..
那么你的变焦很好地工作。
The best way to change the image's width is bind a variable value for it, you can create a converter that divide the width of canvas over two (canvas.width / 2) and bind the width of each image to this converter.. Then your zoom will work perfectly.
这篇关于放大到画布中的所有内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!