每次用户点击Windows Phone中的按钮时如何增加文本框的值?

时间:2016-04-15 14:14:00

标签: c# windows-phone-8.1 windows-phone

嗨,我有这个按钮,在另一页的文本框中显示数字1。 每次用户点击按钮时,我一直在尝试增加文本框值。我已在第一页上将传送的值设置为1。 目前,文本框只显示为2,因为它获取传输数据的值,并在单击按钮时增加到2。

以下是按钮的代码,该按钮将数据传输到下一页并将其显示在文本框中。

我希望每次用户点击按钮时文本框都会递增。

第1页

private void button_Click(object sender, RoutedEventArgs e)
{
    App app = Application.Current as App; // declared the variable "storeValue"in app.cs as an integer.

    app.storeValue = 1; //setting the value as 1 
}

第2页 - 将变量显示在文本框中的代码

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    App app = Application.Current as App;
    app.storeValue++;
    int totalq = int.Parse(textBox.Text) + app.storeValue;
    textBox.Text = totalq.ToString();
}

1 个答案:

答案 0 :(得分:1)

试试这个

第1页

private void button_Click(object sender, RoutedEventArgs e)
{
   App app = Application.Current as App; // declared the variable "storeValue"in app.cs as an integer.

   app.storeValue++;
}

第2页 - 将变量显示在文本框中的代码

protected override void OnNavigatedTo(NavigationEventArgs e)
{
  App app = Application.Current as App;
  //app.storeValue++;
  int totalq = int.Parse(textBox.Text) + app.storeValue;
  textBox.Text = totalq.ToString();
}