C# 禁用pivot中的循环滚动

C# 禁用pivot中的循环滚动,c#,xaml,windows-phone-8.1,windows-phone,winrt-xaml,C#,Xaml,Windows Phone 8.1,Windows Phone,Winrt Xaml,我有一个Win-RT应用程序,Windows phone 8.1和pivot控件 我想禁用循环滚动轴;当最后一项可见时,用户无法立即滚动到第一项,它必须转到上一项 当第一项可见时,它只能转到第二项;无法通过滚动转到最后一个 可能吗 我想做这样的事情,但这真的很难。您可以使用FlipView控件来代替Pivot。在我看来,这是唯一的办法。但如果你真的想要pivot,你可以为SelectionChangedEvent订阅,然后手动检查实际索引并进行更改,如下所示: public sealed par

我有一个Win-RT应用程序,Windows phone 8.1和pivot控件

我想禁用循环滚动轴;当最后一项可见时,用户无法立即滚动到第一项,它必须转到上一项

当第一项可见时,它只能转到第二项;无法通过滚动转到最后一个


可能吗

我想做这样的事情,但这真的很难。您可以使用FlipView控件来代替Pivot。在我看来,这是唯一的办法。但如果你真的想要pivot,你可以为
SelectionChangedEvent
订阅,然后手动检查实际索引并进行更改,如下所示:

public sealed partial class MainPage : Page
{
    private int _selectedIndex = 0;

    public MainPage()
    {
        this.InitializeComponent();

        this.NavigationCacheMode = NavigationCacheMode.Required;
        this.Loaded += OnLoaded;
    }

    private void OnLoaded(object sender, RoutedEventArgs e)
    {
        _selectedIndex = MyPivot.SelectedIndex;
        MyPivot.SelectionChanged += OnSelectionChanged;
    }

    private void OnSelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        if(_selectedIndex == 0 && MyPivot.SelectedIndex == MyPivot.Items.Count-1)
        {
            ChangeSelectedIndex(_selectedIndex);
            return;
        }

        if(_selectedIndex == MyPivot.Items.Count-1 && MyPivot.SelectedIndex == 0)
        {
            ChangeSelectedIndex(_selectedIndex);
            return;
        }

        _selectedIndex = MyPivot.SelectedIndex;
    }

    private void ChangeSelectedIndex(int index)
    {
        Window.Current.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
        {
            MyPivot.SelectedIndex = index;
        });
    }
}
检查一下,但这不是一个好的解决方案,因为当我们尝试从最后一个元素转到第一个元素时,会产生奇怪的视觉效果:)

谢谢:)我也尝试了这个答案,但没有成功。将其更改为flipView并工作。