Issue
I'm have an issue that I can not understand, I want to navigate from MainPage to another page (CheckPage), Then I want to back to the MainPage, Programmatly it's work but there is a white space from the top when I back to the MainPage, See the screenshot
MainPage Code
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="xamrinApp.MainPage">
<StackLayout>
<Grid BackgroundColor="DimGray" HeightRequest="100">
<Label Text="Xamarin App" FontSize="22" Margin="0,50,0,0" HorizontalTextAlignment="Center" TextColor="White"/>
</Grid>
<Label Text="Welcome to Xamarin application" FontSize="Title" Padding="30,10,30,10"/>
<Label Text="Please select from the list:" FontSize="16" Padding="30,0,30,0"/>
<Entry x:Name="enRegistrationNumber" Margin="10"></Entry>
<Button x:Name="btnClickMe" Text="Fetch" Clicked="btnClickMe_Clicked" />
<Label x:Name="laResult" Text="..." HorizontalTextAlignment="Center"></Label>
<Button x:Name="btnCheckRecord" Text="Check Record" Clicked="btnCheckRecord_Clicked"/>
</StackLayout>
Check record button code
App.Current.MainPage = new NavigationPage(new CheckRecordPage());
CheckRecord page code
<ContentPage
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="xamrinApp.Views.CheckRecordPage">
<Grid BackgroundColor="LightYellow">
<Button x:Name="btnBack" Text="Back" Clicked="btnBack_Clicked"></Button>
</Grid>
Back button code
App.Current.MainPage = new NavigationPage(new MainPage());
Solution
That's not how navigation works. Please read the docs
when you first assign the MainPage
in App.xaml.cs
, wrap it in a NavigationPage
MainPage = new NavigationPage(new MyFirstPage());
then when you want to navigation from the first page to the second page
// in MyFirstPage
this.Navigation.PushAsync(new MySecondPage());
when you want to navigate back to the first page, your user can either use the back button, or you can do this programatically
// in MySecondPage
this.Navigation.PopAsync();
Answered By - Jason
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.