none
WinRT中ScrollViewer双击放大或者缩小,官方推荐的方法ChangeView无效。 RRS feed

  • 问题

  • Xaml代码:

    <Grid x:Name="LayoutRoot">
            <ScrollViewer Name="sv" Background="YellowGreen" ZoomMode="Enabled"
                          MaxZoomFactor="2" MinZoomFactor="1"
                          VerticalScrollMode="Enabled" HorizontalScrollMode="Enabled"
                          VerticalScrollBarVisibility="Hidden" HorizontalScrollBarVisibility="Hidden"
                          DoubleTapped="sv_DoubleTapped"
                          >
                <Grid Name="gridBox" MaxWidth="{Binding ActualWidth,ElementName=sv}"
                      MaxHeight="{Binding ActualHeight,ElementName=sv}"
                      HorizontalAlignment="Center" VerticalAlignment="Center"
                      Background="Purple">
                    <Image Source="http://photos.tuchong.com/344025/l/7746122.jpg"/>
                </Grid>
            </ScrollViewer>
        </Grid>

    CS代码:

    private void sv_DoubleTapped(object sender, DoubleTappedRoutedEventArgs e)
            {
                double horizontalOffset = 0;
                double verticalOffset = 0;
                float zoomFactor = 0;
                if (sv.ZoomFactor == 1)
                {
                    if (gridBox.ActualWidth * 2 - sv.ActualWidth > 0)
                        horizontalOffset = gridBox.ActualWidth - sv.ActualWidth / 2;
                    if (gridBox.ActualHeight * 2 - sv.ActualHeight > 0)
                        verticalOffset = gridBox.ActualHeight - sv.ActualHeight / 2;
                    zoomFactor = sv.MaxZoomFactor;
                }
                else
                {
                    horizontalOffset = verticalOffset = 0;
                    zoomFactor = sv.MinZoomFactor;
                }

                //sv.ZoomToFactor(zoomFactor);
                //sv.ScrollToHorizontalOffset(horizontalOffset);
                //sv.ScrollToVerticalOffset(verticalOffset);
                sv.ChangeView(horizontalOffset, verticalOffset, zoomFactor);
            }

    注释的方法代码可以实现效果,但是提示是否决的方法,推荐使用 ChangeView。但是改为现在的代码不能实现效果。

    求助!


    2015年4月20日 10:55

答案

全部回复