Reputation: 618
I have a Win RT app, Windows phone 8.1 with pivot control.
I want to disable circular scrolling pivot; when the last item is visible the user can't scroll to the first immediately, it has to go to the previous one.
And when the first item is visible, it can only go to the second one; can't go to the last one by scrolling.
Is it possible?
Upvotes: 0
Views: 226
Reputation: 781
I wanted to achive something like this, but this is really hard. You can use FlipView control instead Pivot. In my opinion this is only way. But if you really want pivot, you can subsribe for SelectionChangedEvent
and manually check actual index and change it, sth like this:
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;
});
}
}
Check that, but this isn't good solution because we have weird visual effect when we're trying to go from last to first element :)
Upvotes: 2