可以在Windows Phone 8.1上支持ViewportControl吗?

时间:2014-10-02 04:00:12

标签: windows windows-phone-8 nuget windows-phone-8.1 nuget-package

现在,我希望放大或缩小列表视图中的图片。人们已经向我分享了这些问题,但它使用的是Windows Phone 8.1不支持的ViewportControl。

1 个答案:

答案 0 :(得分:1)

Silverlight 8.1应用支持ViewportControl。 Windows Phone运行时应用程序不支持它。

您可以使用ScrollViewer来放大或缩小图片:

<ScrollViewer x:Name="scrollViewer" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" 
              VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" 
              ZoomMode="Enabled" MinZoomFactor="0.7">
    <Grid Height="200" Width="300">
        <Image AutomationProperties.Name="Cute kitten picture" Source="Assets/gracie.jpg" Stretch="Uniform" HorizontalAlignment="Center" VerticalAlignment="Center"/>
    </Grid>
</ScrollViewer>

或者您可以处理操纵事件以直接缩放图片。

<Image AutomationProperties.Name="Cute kitten picture" Source="Assets/gracie.jpg" 
       Stretch="Uniform"
       ManipulationMode="Scale"
       ManipulationDelta="Image_ManipulationDelta" 
       RenderTransformOrigin="0.5,0.5">
    <Image.RenderTransform>
        <CompositeTransform />
    </Image.RenderTransform>
</Image>

C#

double minScale = 0.7;
private void Image_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
{
    Image img = sender as Image;
    CompositeTransform ct = img.RenderTransform as CompositeTransform;

    ct.ScaleX *= e.Delta.Scale;
    ct.ScaleY *= e.Delta.Scale;

    if (ct.ScaleX < minScale) ct.ScaleX = minScale;
    if (ct.ScaleY < minScale) ct.ScaleY = minScale;
}

请参阅XAML scrolling, panning, and zooming sample以演示使用ScrollViewer进行缩放。

有关处理操作的详细信息,请参阅Quickstart: Touch input