Could the ViewportControl support on windows phone 8.1?

陌路散爱 提交于 2019-12-08 09:35:23

问题


Now, I want zoom in or out the picture on listviews. The people had share to me that these question but It use ViewportControl that windows phone 8.1 is not support.


回答1:


The ViewportControl is supported for Silverlight 8.1 apps. It is not supported for Windows Phone Runtime apps.

You can use a ScrollViewer to allow a picture to zoom in or out:

<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>

Or you can handle manipulation events to zoom the picture directly.

<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;
}

See the XAML scrolling, panning, and zooming sample to demonstrate zooming with a ScrollViewer.

See Quickstart: Touch input for more info on handling manipulations.



来源:https://stackoverflow.com/questions/26154318/could-the-viewportcontrol-support-on-windows-phone-8-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!