ScrollViewer 跳回左边框

ScrollViewer jumps back to left border

我有一个 ScrollViewer,里面有一个图像。每次我将图像缩放到大于我的屏幕时,它都会弹回左边框。奇怪的是只有左边,而不是顶部,即使图像比我的屏幕大,宽度和高度也是如此。 BringIntoViewOnFocusChange 似乎没有帮助。

<UserControl>
    <Grid>
        <ScrollViewer ZoomMode="Enabled"
              HorizontalAlignment="Stretch" VerticalAlignment="Stretch" BringIntoViewOnFocusChange="False" >
            <Image ScrollViewer.BringIntoViewOnFocusChange="False" HorizontalAlignment="Center" VerticalAlignment="Center" />
        </ScrollViewer>
    </Grid>
</UserControl>

This 答案解决了问题。如果不想影响图像大小,可以使用 ScrollViewer

ViewportHeightViewportWidth 属性
  <Image Width="{Binding ElementName=scrollViewer, Path=ViewportWidth}"
         Height="{Binding ElementName=scrollViewer, Path=ViewportHeight}"
         ScrollViewer.BringIntoViewOnFocusChange="False"
         HorizontalAlignment="Center"
         VerticalAlignment="Center"
         Source="Assets/image.jpg" />