C# 在FlipView中使用ScrollViewer
我有一个带有FlipView的Windows Phone 8.1应用程序。每个FlipView项目表示一个杂志页面(PDF页面渲染为位图,并带有一些覆盖) 我需要为所有页面启用“收缩”以缩放。我的FlipView项目模板如下所示C# 在FlipView中使用ScrollViewer,c#,xaml,windows-phone-8,windows-phone-8.1,C#,Xaml,Windows Phone 8,Windows Phone 8.1,我有一个带有FlipView的Windows Phone 8.1应用程序。每个FlipView项目表示一个杂志页面(PDF页面渲染为位图,并带有一些覆盖) 我需要为所有页面启用“收缩”以缩放。我的FlipView项目模板如下所示 <DataTemplate x:Key="SinglePageTemplate"> <ScrollViewer ZoomMode="Enabled">
<DataTemplate
x:Key="SinglePageTemplate">
<ScrollViewer
ZoomMode="Enabled">
<Grid>
<ProgressRing
HorizontalAlignment="Center"
VerticalAlignment="Center"
IsActive="{Binding IsRendered, Converter={StaticResource BooleanNegateConverter}}" />
<Image
Source="{Binding Bitmap}"
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch">
</Image>
</Grid>
</ScrollViewer>
问题是,当我缩小页面并尝试将其向右移动时,它总是“跳”回左侧
以下是一段视频,显示了问题:
你知道为什么以及如何修复它吗?在scrollviewer中,你必须手动启用ScrollBarVisibility和mode
<ScrollViewer ZoomMode="Enabled"
HorizontalScrollBarVisibility="Visible"
VerticalScrollBarVisibility="Visible"
HorizontalScrollMode="Enabled"
VerticalScrollMode="Enabled">
<Grid>
<ProgressRing
HorizontalAlignment="Center"
VerticalAlignment="Center"
IsActive="{Binding IsRendered, Converter={StaticResource BooleanNegateConverter}}" />
<Image
Source="{Binding Bitmap}"
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch">
</Image>
</Grid>
</ScrollViewer>
您还可以选择设置Max/MinZoomFactor以防止过度缩放我也有同样的问题。我通过使用附加的行为和设置解决了这个问题。
HorizontalScrollBarVisibility=“Visible”VerticalScrollBarVisibility=“Visible”
下面是用于附加行为的代码
public class PanAndZoomBehavior : Behavior<ScrollViewer>
{
protected override void OnAttached()
{
base.OnAttached();
Window.Current.SizeChanged += OnSizeChanged;
SetElementSize();
}
protected override void OnDetaching()
{
base.OnDetaching();
Window.Current.SizeChanged -= OnSizeChanged;
}
private void OnSizeChanged(object sender, Windows.UI.Core.WindowSizeChangedEventArgs e)
{
SetElementSize();
}
private void SetElementSize()
{
AssociatedObject.Width = Window.Current.Bounds.Width;
AssociatedObject.Height = Window.Current.Bounds.Height;
if (AssociatedObject.Content != null)
{
FrameworkElement element = (FrameworkElement)AssociatedObject.Content;
element.Width = Window.Current.Bounds.Width;
element.Height = Window.Current.Bounds.Height;
}
}
}
公共类PanAndZoomBehavior:行为
{
受保护的覆盖无效附加()
{
base.onatached();
Window.Current.SizeChanged+=OnSizeChanged;
SetElementSize();
}
附加时受保护的覆盖无效()
{
base.OnDetaching();
Window.Current.SizeChanged-=OnSizeChanged;
}
私有无效OnSizeChanged(对象发送方,Windows.UI.Core.WindowSizeChangedEventArgs e)
{
SetElementSize();
}
私有void SetElementSize()
{
AssociatedObject.Width=Window.Current.Bounds.Width;
AssociatedObject.Height=Window.Current.Bounds.Height;
if(AssociatedObject.Content!=null)
{
FrameworkElement=(FrameworkElement)AssociatedObject.Content;
element.Width=Window.Current.Bounds.Width;
element.Height=Window.Current.Bounds.Height;
}
}
}
将此行为应用于ScrollViewer,我想我知道这里发生了什么。当您完全缩小并尝试在上面滑动时,实际上是在FlipView项目中滑动,而不是在父容器中。我在Windows 8.1上遇到了一个非常类似的问题。几乎相同的情景。我发现在ScrollViewer中将水平和垂直ScrollBarVisibility设置为Auto有帮助,但是如果呈现的PDF页面的分辨率大于屏幕分辨率(通常情况下,为了使缩放正常工作),则呈现的页面太大。所以我做的另一件事是将网格的最大宽度限制为Window.Current.Bounds.width,最大高度限制为相同的宽度乘以基于杂志页面格式的比例因子。然后它就开始工作了。看起来像是击中了,你可以试着把这些属性设置成MandatorySingle或NoneIgor,你解决了这个问题吗?我也面临着同样的问题。@Alexandr尝试一下: