键入值并单击按钮存款时,如何增加值数量



我可以输入我要存入的数量,然后单击时,当存入时,应增加键入多少的金额。如何增加一开始时应为0的金额值。

我正在使用C#跨平台应用程序。

//mainpage.xaml

     <Label x:Name="Balance0"
           Text="Amount"
           FontSize="Large"
           VerticalOptions="CenterAndExpand"
           HorizontalOptions="Center" />
    <Editor Keyboard="Numeric"  />
    <Button Text="Deposit"
            VerticalOptions="CenterAndExpand"
            HorizontalOptions="Center"
            Command="{Binding DepositCommand}"/>

//apiservices.cs

    public void Deposit(int Increment)
    {
        int Amount = 0;
        Amount += Increment;
    }

//positeviewmodel.cs

class DepositViewModel
{
    ApiServices _apiServices = new ApiServices();
    public int Increment { get; set; }
    public ICommand Deposit
    {
        get
        {
            return new Command(async () =>
            {
                 _apiServices.Deposit(Increment);
            });
        }}}

您需要给您的编辑器控制一个名称,或使用databinding

// assume editor is named editDeposit, and contains an int value
// if the input is not a valid int, this will throw an exception
int deposit = Int.Parse(editDeposit.Text);
// increment the Amount
Amount += deposit;

最新更新