You can use the Shell.TitleView
to show the back button. And handle the button's clicked event to go back to MainPage:
<Shell.TitleView><Grid ColumnDefinitions="2*,8*"><Button Text="Back" Clicked="Button_Clicked" HorizontalOptions="Start" Grid.Column="0"/></Grid></Shell.TitleView>
And in the code behind:
private void Button_Clicked(object sender, EventArgs e) { Shell.Current.GoToAsync("///MainPage"); }
And you can show or hide the button by checking if the current page is rootpage or not.