【问题标题】:Disable circular scrolling in pivot禁用枢轴中的循环滚动
【发布时间】:2015-12-14 02:32:39
【问题描述】:

我有一个 Win RT 应用程序,Windows phone 8.1 带有枢轴控制。

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

而当第一项可见时,只能到第二项;无法滚动到最后一个。

有可能吗?

【问题讨论】:

    标签: c# xaml windows-phone-8.1 windows-phone winrt-xaml


    【解决方案1】:

    我想实现这样的目标,但这真的很难。您可以使用 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 并工作。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-25
    • 2011-05-15
    • 1970-01-01
    • 2013-06-20
    • 1970-01-01
    • 2020-08-14
    相关资源
    最近更新 更多