2015-11-12 26 views
0

我在ScrollViewer中有一個帶有圖像的網格。用戶需要能夠放大和縮小圖像。問題是,當我縮放scrollviewer似乎回彈到圖像的左側,雖然我希望觀衆留在放大的位置。該XAML代碼看起來像這樣在XAML的ScrollViewer中禁用捕捉點/反彈

<ScrollViewer Name="ScrollViewer" HorizontalSnapPointsType="None" VerticalSnapPointsType="None" ZoomSnapPointsType="None"> 
    <Grid x:Name="RenderedGrid" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> 
     <Image x:Name="RenderedImage" Stretch="Fill" /> 
     <canvas:CanvasControl Name="DrawingCanvas" Draw="CanvasControl_Draw" ClearColor="Transparent"/> 

    </Grid> 
</ScrollViewer> 

我認爲這將是足以與設置SnapPointType爲「無」,但這似乎並沒有工作。

回答

2

我寫了一篇博客文章正是這個問題:Why is my zoomable ScrollViewer snapping the image to the left?

問題的第一部分是ScrollViewer中本身,它需要HorizontalScrollBarVisibilityVerticalScrollBarVisibility設置爲自動。

<ScrollViewer ZoomMode="Enabled" 
       MinZoomFactor="1" 
       MaxZoomFactor="4" 
       HorizontalScrollBarVisibility="Auto" 
       VerticalScrollBarVisibility="Auto"> 

對於真正的工作,你需要的圖片大小限制爲一些寬/高,像這樣:

<Image Source="{Binding ImageUri}" 
     MaxWidth="{Binding DataContext.PageWidth, ElementName=MyPage}" 
     MaxHeight="{Binding DataContext.PageHeight, ElementName=MyPage}"/> 

你可以在我的博客中找到更多的詳細信息,以及全源代碼GitHub

+0

太棒了!奇蹟般有效!奇怪的是,當谷歌搜索時,我沒有找到你的博客文章。 – stonecompass