Reputation: 11951
On click on the navigate button, system throws exception in my xamarin.Form app. I am trying to get the email
text value and display in the Home
page.
Exception: Unhandled Exception: System.InvalidOperationException:
<Timeout exceeded getting exception details>`
MainPage.xaml.cs;
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
var emailText = emailEntry.Text;
var passwordText = passwordEntry.Text;
}
int count = 0;
public void Button_Clicked(object sender, System.EventArgs e)
{
string text = emailEntry.Text;
}
public async void NavigateButton_OnClicked(object sender, EventArgs e)
{
await Navigation.PushAsync(new Home(emailEntry.Text));
}
}
Following is my Home.xaml.cs
where I need to display the text email value from the MainPage.xaml.cs;
public partial class Home : ContentPage
{
public Home(string parameter1)
{
InitializeComponent();
HomeLabel.Text = parameter1;
}
}
App.xaml.cs details below;
public partial class App : Application
{
string parameter1;
public App()
{
InitializeComponent();
var tabbedPage = new TabbedPage();
tabbedPage.Children.Add(new Home(parameter1));
tabbedPage.Children.Add(new Map());
tabbedPage.Children.Add(new Settings());
MainPage = new MainPage();
//MainPage = new TabbedPage();
//MainPage = tabbedPage;
}
protected override void OnStart()
{
// Handle when your app starts
}
protected override void OnSleep()
{
// Handle when your app sleeps
}
protected override void OnResume()
{
// Handle when your app resumes
}
}
MainPage.xaml
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:soccerapp"
x:Class="soccerapp.MainPage">
<StackLayout Spacing="20" Padding="50">
<Entry x:Name="emailEntry" Placeholder="Email Id"></Entry>
<Entry x:Name="passwordEntry" Placeholder="Password" IsPassword="True"></Entry>
<Button Text="Log In" Clicked="Button_Clicked" TextColor="White" BackgroundColor="#404751"></Button>
<Button Text="Navigate to Home" Clicked="NavigateButton_OnClicked" TextColor="White" BackgroundColor="ForestGreen"></Button>
<!-- Place new controls here -->
<Label Text="Welcome Mate!" HorizontalOptions="Center" VerticalOptions="CenterAndExpand" />
</StackLayout>
</ContentPage>
Home.xaml:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="soccerapp.Home" BackgroundColor="GreenYellow" Title="Home">
<ContentPage.Content>
<StackLayout>
<Label x:Name="HomeLabel" Text="Home Page is here" TextColor="White"
VerticalOptions="CenterAndExpand"
HorizontalOptions="CenterAndExpand"></Label>
</StackLayout>
</ContentPage.Content>
</ContentPage>
Upvotes: 0
Views: 116
Reputation: 666
Ok, first of all you have to create NavigationPage
in you App.xaml.cs. Also, you need to move your TabbedPage
initialization into separate xaml
file or in NavigationsClicked
event.
public App()
{
InitializeComponent();
MainPage = new NavigationPage(new MainPage());
}
Create your TabbedPage in NavigationClicked
event:
public async void NavigateButton_OnClicked(object sender, EventArgs e)
{
var tabbedPage = new TabbedPage();
tabbedPage.Children.Add(new Home(parameter1));
tabbedPage.Children.Add(new Map());
tabbedPage.Children.Add(new Settings());
await Navigation.PushAsync(tabbedPage);
}
or create new XAML file for TabbedPage
:
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MyTabbedPage">
<!--Pages can be added as references or inline-->
<ContentPage Title="HomeTitle">
<!--Content for Home Page-->
</ContentPage>
<ContentPage Title="MapTitle">
<!--Content for Map Page-->
</ContentPage>
<ContentPage Title="SettingsTitle">
<!--Content for Settings Page-->
</ContentPage>
</TabbedPage>
Upvotes: 1