I am facing an issue with FlipView. I am sharing the minimalistic project, which represent my usecase in original app, http://1drv.ms/163kHCR.
I have two pages. First is MainPage.xaml. It has a flipview with five times. First four has just textblock and fifth one has one button. Clicking on it I will be redirected to Next.xaml. Please note MainPage has NavigationCacheMode as NavigationCacheMode.Required [Which is required for my original app]. So last known index of FlipView is 4.
In Next page there's a button clicking on it, opens the mail client via launcher. Now when I press back from mail client I would be navigated to Next page and pressing back one more time, I will be on MainPage and selected index will be 4, that's correct. Now when I swipe to right to see FlipViewItem with index 3, it immediately show me first FlipViewItem with index 0. It just skips all the items till index 0.
Is there anything wrong in the code?
MainPage.Xaml
<Grid Grid.Row="1" x:Name="ContentRoot">
<FlipView x:Name="fv">
<FlipViewItem>
<TextBlock Text="1" FontSize="50" />
</FlipViewItem>
<FlipViewItem>
<TextBlock Text="2" FontSize="50" />
</FlipViewItem>
<FlipViewItem>
<TextBlock Text="3" FontSize="50" />
</FlipViewItem>
<FlipViewItem>
<TextBlock Text="4" FontSize="50" />
</FlipViewItem>
<FlipViewItem>
<Button Content="Next" Click="btnNext_Click" />
</FlipViewItem>
</FlipView>
</Grid>
MainPage.Xaml.cs
public MainPage()
{
this.InitializeComponent();
this.navigationHelper = new NavigationHelper(this);
this.navigationHelper.LoadState += this.NavigationHelper_LoadState;
this.navigationHelper.SaveState += this.NavigationHelper_SaveState;
NavigationCacheMode = NavigationCacheMode.Required;
}
private void btnNext_Click(object sender, RoutedEventArgs e)
{
Frame.Navigate(typeof(Next));
}
Next.xaml (NavigationCacheMode is not set)
<Grid Grid.Row="1" x:Name="ContentRoot">
<Button Content="Mail" Click="btnMail_Click" />
</Grid>
Next.xaml.cs
private async void btnMail_Click(object sender, RoutedEventArgs e)
{
var mailto = "mailto:?to=windows@microsoft.com&subject=Email&body=body";
await Windows.System.Launcher.LaunchUriAsync(new Uri(mailto));
}
This seems like a known bug that affects the FlipView
control when you get back to it in a cached page. Not sure what the best workaround is, but you could try a few things - calling InvalidateScrollInfo()
on the ScrollViewer
in the FlipView's
template, resetting the SelectedIndex
value (perhaps set it to some other value and then immediately to the previous one), maybe even reset ItemsSource
.