Good morning,
we would like to extract the currently active view out of the shell. We are using Xamarin.Forms 4.0.0.540366 as it is the latest stable version.
The exact situation is that we have two tabs on the bottom which navigate to different views. Both views contain a ListView, which execute PushAsync on selecting an item. When calling PopAsync we previously used OnAppearing for reloading the data, but that is not getting called anymore.
Instead we found out that, on every type of navigation, OnNavigated(ShellNavigatedEventArgs) in the shell is geting called. We tried to extract the active view out of there, but didn't manage to do so.
`
protected override void OnNavigated(ShellNavigatedEventArgs args)
{
base.OnNavigated(args);
if (Shell.Current?.CurrentItem == null) return;
// We did see that Shell.Current?.CurrentItem -> expand base -> CurrentItem.PresentedPage has the page we are looking for.
var c = Shell.Current?.CurrentItem;
if (Shell.Current?.CurrentItem is ShellGroupItem group)
{
if (Shell.Current is Page p)
{
var s = p.ToString();
}
if (group is ShellItem baseitm)
{
if (baseitm.CurrentItem is ShellSection section)
{
var ctx = section.BindingContext;
var cnt = section.CurrentItem;
var itm = section.Items.FirstOrDefault();
var a = Shell.Current.Navigation.NavigationStack; // first item on the stack null?
// itm.Page and cnt.Page -> contains the page aswell, cant be extracted
}
}
}
}`
Why is the first page on the NavigationStack null? This seems to be a bug to us.
How can we now get the active view to reload data after PopAsync?