简体   繁体   English

Windows Phone 8.1中的ScrollViewer中的图像

[英]Image in a ScrollViewer in Windows Phone 8.1

I have a FlipView which shows the pages of a leaflet as the user swipes through it. 我有一个FlipView,当用户在其中浏览传单时会显示传单的页面。 I want the user to be able to zoom in a page. 我希望用户能够放大页面。 What I found so far is that if I wrap my Image inside a ScrollViewer and set ZoomMode = Enabled , the user can zoom. 到目前为止,我发现如果将Image包裹在ScrollViewer中并设置ZoomMode = Enabled ,则用户可以缩放。 The strange thing is that if I zoom in the right side of the page, it automatically goes back to the left side after I lift up my fingers from the screen. 奇怪的是,如果我放大页面的右侧,当我从屏幕上抬起手指时,它会自动返回到左侧。 Any idea how to solve this issue? 任何想法如何解决这个问题?

XAML: XAML:

<Grid Name="grRoot">
    <FlipView x:Name="flipView1"
              BorderBrush="Black"
              ItemsSource="{Binding}">

        <FlipView.ItemTemplate>
            <DataTemplate>
                <ScrollViewer ZoomMode="Enabled" MinZoomFactor="1">
                    <Image Source="{Binding url_dotcom}"
                           Stretch="Fill" 
                           Holding="imgHolding"/>
                </ScrollViewer>
            </DataTemplate>
        </FlipView.ItemTemplate>
    </FlipView>
</Grid>

Setting the FlipView's width and height: 设置FlipView的宽度和高度:

flipView1.Width = Window.Current.Bounds.Width;
flipView1.Height = Window.Current.Bounds.Height;

Try something like this: 尝试这样的事情:

<Grid Name="grRoot">
    <FlipView x:Name="flipView1"
              BorderBrush="Black"
              ItemsSource="{Binding}">

        <FlipView.ItemTemplate>
            <DataTemplate>
                <ScrollViewer ZoomMode="Enabled" MinZoomFactor="1"
                              HorizontalScrollBarVisibility="Auto"
                              VerticalScrollBarVisibility="Auto">
                    <Image Source="{Binding url_dotcom}"
                           Stretch="Fill" 
                           Holding="imgHolding"
                           MaxWidth="{Binding ElementName=YourPage, Path=DataContext.Width}"
                           MaxHeight="{Binding ElementName=YourPage, Path=DataContext.Height}"/>
                </ScrollViewer>
            </DataTemplate>
        </FlipView.ItemTemplate>
    </FlipView>
</Grid>

There are 2 important changes here: 这里有2个重要更改:

  • Set ScrollViewer's HorizontalScrollBarVisibility and VerticalScrollBarVisibility to Auto 将ScrollViewer的Horizo​​ntalScrollBarVisibility和VerticalScrollBarVisibility设置为Auto
  • Bind Image's MaxWidth and MaxHeight to Window.Current.Bounds.Width and Window.Current.Bounds.Height respectively exposed through Width and Height public properties inside a ViewModel that is a DataContext to that specific page. 将图像的MaxWidth和MaxHeight绑定到分别通过ViewModel内部的Width和Height公共属性公开的Window.Current.Bounds.Width和Window.Current.Bounds.Height,该ViewModel是该特定页面的DataContext。 This is for scenarios where your FlipView is taking up the whole page. 这适用于FlipView占用整个页面的情况。 If you need the FlipView to be smaller on the page, then set the Width and Height properties in the ViewModel based on the size you expect/need/want. 如果您需要FlipView在页面上变小,则根据您期望/需要/想要的大小在ViewModel中设置Width和Height属性。

EDIT: More info in my blog post Why is my zoomable ScrollViewer snapping the image to the left? 编辑:我的博客文章中的更多信息为什么我的可缩放ScrollViewer将图像捕捉到左侧?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM