Search code examples
c#xamlxamarinxamarin.formsxamarin.android

Problems with binding xamarin


Sorry for the stupid question I have binding to object but the label does not show field of the object

<Label x:Name="meow" Text="{Binding MeClient2.Name}" FontSize="25" FontAttributes="Bold" ForegroundColor="Black" />

code behind

 public Client MeClient2 { get; set; }
        public Profile(Client client)
        {
            Device.SetFlags(new string[] { "AppTheme_Experimental" });
            InitializeComponent();
             MeClient2 = client;
         }

code behind from previous page

public Client MeClient { get; set; }
        public LoginPage()
        {
            Device.SetFlags(new string[] { "AppTheme_Experimental" });
            InitializeComponent();
           
            MeClient = new Client
            {
                Name = "M ",
                FirstName = "K",
                Phone = "+382457412365",
                Card = "5375 4141 0000 0000",
                PasswordCard = 1234,
                PasswordApp = 4321,
                Money = 5000,
                State = true
            };

          
        }
        private async void LoginNext(object sender, EventArgs e)
        {
         if(PhoneName.Text== MeClient.Phone && PasswordName.Text=="4321")
            {
                  await Navigation.PushModalAsync(new Profile(MeClient));
            }
         else
            {
                _ = DisplayAlert("Error", "L/P", "ОK");
            }
        }

Label must show M but there is nothing


Solution

  • you are not setting a BindingContext

    public Profile(Client client)
        {
            Device.SetFlags(new string[] { "AppTheme_Experimental" });
            InitializeComponent();
            MeClient2 = client;
            this.BindingContext = this;
         }