我有其他建议,我也遇到过类似的问题,但我想禁用弹跳,当翻转视图中只有 1 个元素时。
所以我这样做了:
创建了一个模板控件:
CustomFlipView 和它继承自 FlipView:
public sealed class CustomFlipView : FlipView
接下来,我编辑了 FlipViewStyle 以获得 FlipView 的样式代码(是的,那个大的)。
并复制粘贴到Generic.xaml中,生成
<Style TargetType="local:CustomFlipView">
因此,这让我有机会将名称添加到默认情况下未命名的此类 xaml 控件。
我为 ItemsPresenter 添加了一个名称:
<ScrollViewer x:Name="ScrollingHost" AutomationProperties.AccessibilityView="Raw" BringIntoViewOnFocusChange="{TemplateBinding ScrollViewer.BringIntoViewOnFocusChange}" HorizontalScrollMode="{TemplateBinding ScrollViewer.HorizontalScrollMode}" HorizontalSnapPointsType="MandatorySingle" HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}" IsTabStop="False" IsHorizontalRailEnabled="{TemplateBinding ScrollViewer.IsHorizontalRailEnabled}" IsHorizontalScrollChainingEnabled="{TemplateBinding ScrollViewer.IsHorizontalScrollChainingEnabled}" IsVerticalScrollChainingEnabled="{TemplateBinding ScrollViewer.IsVerticalScrollChainingEnabled}" IsVerticalRailEnabled="{TemplateBinding ScrollViewer.IsVerticalRailEnabled}" IsDeferredScrollingEnabled="{TemplateBinding ScrollViewer.IsDeferredScrollingEnabled}" Padding="{TemplateBinding Padding}" TabNavigation="{TemplateBinding TabNavigation}" VerticalSnapPointsType="MandatorySingle" VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}" VerticalScrollMode="{TemplateBinding ScrollViewer.VerticalScrollMode}" ZoomMode="Disabled">
<ItemsPresenter x:Name="FlipViewItemsPresenter"/>
</ScrollViewer>
接下来在 CustomFlipView 的代码中,我这样做了:
public sealed class CustomFlipView : FlipView //this line is indented.
{
private ItemsPresenter itemsPresenter;
public CustomFlipView()
{
this.DefaultStyleKey = typeof(CustomFlipView);
}
protected override void OnApplyTemplate()
{
base.OnApplyTemplate();
itemsPresenter = GetTemplateChild("FlipViewItemsPresenter") as ItemsPresenter;
FixateItems();
}
protected override void OnItemsChanged(object e)
{
base.OnItemsChanged(e);
FixateItems();
}
private void FixateItems()
{
if (itemsPresenter != null)
{
if (this.Items.Count < 2)
{
itemsPresenter.ManipulationMode = ManipulationModes.None;
}
else
{
itemsPresenter.ManipulationMode = ManipulationModes.System;
}
}
}
}
希望这能给你一个提示。