在UWP中缩放InkCanvas的简单方法?

时间:2016-12-02 01:44:03

标签: uwp zoom scrollviewer inkcanvas

我正在尝试放大InkCanvas。

我的第一个想法是:

<ScrollViewer ZoomMode="True">
   <InkCanvas>
   </InkCanvas>
</ScrollViewer>

但这种方式不起作用。

我把它放入ScrollViewer后,我无法在Canvas上写任何东西。

也许有人可以提供帮助。

由于

Agredo

2 个答案:

答案 0 :(得分:0)

刚刚建立了一个小概念验证,我开始工作了!

这是XAML:

<ScrollViewer ZoomMode="Enabled" MinZoomFactor="1" MaxZoomFactor="7"                               HorizontalScrollBarVisibility="Visible" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
              VerticalScrollBarVisibility="Visible" Height="275" Width="525" BorderBrush="LightBlue" BorderThickness="2">
    <Border BorderBrush="Black" BorderThickness="2" Height="250" Width="500">
        <InkCanvas x:Name="InkCanvas" Loaded="InkCanvas_Loaded"/>
    </Border>
</ScrollViewer>  

我将Ink Canvas和Scrollviewer包裹在一起,这样你就可以看到它们相对于彼此的位置。这也是InkCanvas_Loaded方法:

  private void InkCanvas_Loaded(object sender, RoutedEventArgs e)
    {
        InkCanvas canvas = sender as InkCanvas;

        //Set inputs
        canvas.InkPresenter.InputDeviceTypes =
            Windows.UI.Core.CoreInputDeviceTypes.Mouse |
            Windows.UI.Core.CoreInputDeviceTypes.Pen |
            Windows.UI.Core.CoreInputDeviceTypes.Touch;

        // Set initial ink stroke attributes.
        InkDrawingAttributes drawingAttributes = new InkDrawingAttributes();
        drawingAttributes.Size = new Size(10, 10);
        drawingAttributes.Color = Windows.UI.Colors.Black;
        drawingAttributes.IgnorePressure = false;
        drawingAttributes.FitToCurve = true;
        canvas.InkPresenter.UpdateDefaultDrawingAttributes(drawingAttributes);
    }

您可以通过按住控件并向上或向下移动鼠标中键来滚动。如果您在触摸屏上,可以捏合/扩展以放大/缩小!

答案 1 :(得分:0)

您可能需要将ZoomMode从“True”更改为“Enabled”,并为画布添加高度;某些控件默认不会拉伸他们的孩子。

这对我有用:

     <ScrollViewer x:Name="scrollViewer" ZoomMode="Enabled" MinZoomFactor="1" VerticalScrollMode="Enabled" VerticalScrollBarVisibility="Auto" HorizontalScrollMode="Enabled" HorizontalScrollBarVisibility="Auto">
        <Grid x:Name="outputGrid" Background="{ThemeResource SystemControlBackgroundChromeWhiteBrush}" Height="Auto">
            <InkCanvas x:Name="inkCanvas"/>
        </Grid>
    </ScrollViewer>