Xamarin Forms - TabbedPage - Pass Parameter

370 Views Asked by At

I have a TappedPage like so:

<?xml version="1.0" encoding="UTF-8"?>
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="using:MyApp" x:Class="MyApp.AccountPatientPage" Title="Account">
    <local:PatientConditions IconImageSource="user.png" />
    <local:PatientPainKillers IconImageSource="user.png"  />
    <local:PatientPainStory IconImageSource="user.png"  />
</TabbedPage>

and here is the code behind:

public partial class PatientProfilePage : TabbedPage
    {
        public PatientProfilePage(string username)
        {
            InitializeComponent();
        }
    }

My question is how can I pass the string username to the other pages? Here is an example of one.

public partial class PatientConditions : ContentPage
    {
        public PatientConditions(string username)
        {
            InitializeComponent();
        }
    }
1

There are 1 best solutions below

0
On

your pages will inherit their parent's BindingContext unless you specify differently

// some custom class that contains properties for username and anything 
// else you need
MyViewModel vm;

public PatientProfilePage(string username)
{
    InitializeComponent();

    this.BindingContext = vm = new MyViewModel(username);
}