I would like to refresh a content page, i.e. completely reload it, when I tap on the page in the tab bar.
I have tried numerous ways without success. Could you please help me?
AppShell.xaml
<TabBar>
<Tab Title="Dashboard">
<ShellContent
x:Name="DashboardPage"
Shell.NavBarIsVisible="false"
ContentTemplate="{DataTemplate local:Dashboard}"
Appearing="ReloadDashboard" />
</Tab>
<!--Some other tabs-->
</TabBar>
AppShell.xaml.cs
public partial class AppShell : Shell
{
public AppShell()
{
InitializeComponent();
}
private void ReloadDashboard(object sender, EventArgs e)
{
//Code to reload the content page "Dashboard"
}
}
Thanks in advance!
Answer from Kristof Berge should be accepted as the correct one, however if reload of entire page is intended one would rather use Content property of ShellItem instead of ContentTemplate one, heres a simple example:
<TabBar>
<Tab Title="Dashboard">
<ShellContent x:Name="dPage"
Shell.NavBarIsVisible="false"
ContentTemplate="{x:Null}"
/>
</Tab>
<!--Some other tabs-->
</TabBar>
public partial class AppShell : Shell
{
public AppShell()
{
InitializeComponent();
dPage.Content = new DashboardPage();
dPage.Appearing += OnDashLoaded;
}
public void OnDashLoaded(object sender, EventArgs e){
var oldPage = dPage.Content as DashboarPage;
dPage.Content = new DashboardPage {Handler = oldPage.Handler};
}
}
In this example I am refreshing page during Appearing event which is definetly not the most eficent way to do it, but it works.
It is also important in this case to set ContentTemplate to null and also pass Handler from old page to a new one since it won't be attached and will remain null on the new page.