I can't change the value of the .Text property of a MainPage label from the Code Behind of another

I'm creating a simple app, where I have a 10 Pages, 3 of those are MainPage, PayPage and the RechargePage, on PayPage i have an entry to catch the amount to Pay, on Recharge i have other to catch the value to recharge, and on the MainPage i have a label to show the available balance, so I have to update the balance adding in PayPage and subtracting in RechargePage, but when I try to change the BalanceLabel.Text property the value doesn't update.

I'm Using a MasterDetailPage to navegate in the app.

I would like to know what I am doing wrong!

this is the part of the code in RechargePage where I try to change the Label:

private void ProcesarRecargo_Clicked(object sender, EventArgs e)
        {

            if (String.IsNullOrEmpty(EntryToRecharge.Text))
            {
                DisplayAlert("Error", "Debe ingresar un valor valido", "Reintentar");
                EntryToRecharge.Text = String.Empty;
            }
            else if (Convert.ToDouble(EntryToRecharge.Text) > 0)
            {
                DisplayAlert(" ", "RD$ " + EntryToRecharge.Text + " recargados exitosamente", "Continuar");
                MainPage main = new MainPage(EntryToRecharge.Text);
                main.Recargar();
            }

        }

Part of the code in PayPage:

        private void ProcesarPago_Clicked(object sender, EventArgs e)
                {
                    if (Convert.ToDouble(EntryToPay.Text) <= 0 || String.IsNullOrEmpty(EntryToPay.Text))
                    {
                        DisplayAlert("Error", "Debe ingresar un valor valido", "Reintentar");
                        EntryToPay.Text = String.Empty;
                    }
                    else if (Convert.ToDouble(EntryToPay.Text) > 0)
                    {
                        MainPage main = new MainPage(EntryToPay.Text);
                        main.Pagar();
                    }

                }

And the code in MainPage:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;

namespace Chelitos.Views
{

    public partial class MainPage : ContentPage
    {
        public string value;
        public string NewBalance;

        public MainPage(string value_received)
        {
            InitializeComponent();
            value = value_received;            
        }


        public void Recargar()
        {
            double actual = 0;

            if (double.TryParse(BalanceLabel.Text, out double i) == false)
            {
                BalanceLabel.Text = value;
            }

            else if (Convert.ToDouble(BalanceLabel.Text) >= 0)
            {
                actual += Convert.ToDouble(value);
            }

            BalanceLabel.Text = actual.ToString();
        }

        public void Pagar()
        {

            double actual = Convert.ToDouble(BalanceLabel.Text);

            if (double.TryParse(BalanceLabel.Text, out double i) == false)
            {
                DisplayAlert("Error", "Saldo insuficiente, debe recargar", "OK");
            }

            else if (actual < Convert.ToDouble(value))
            {
                DisplayAlert("Error", "Saldo insuficiente, debe recargar", "OK");
            }

            else if (Convert.ToDouble(value) >= actual)
            {
                actual = actual - Convert.ToDouble(value);
            }

            BalanceLabel.Text = actual.ToString();
        }

    }
}
Sign In or Register to comment.