[英]automatically update textBox windows phone 8/C#
wassup伙计们,我进行了搜索,发现了几则帖子,他们帮了忙,但由于某种原因,它无法完全正常工作
好的,这是我的代码:
if (!string.IsNullOrEmpty(amountBox1.Text) && !string.IsNullOrEmpty(amountBox2.Text) && !string.IsNullOrEmpty(amountBox3.Text) && !string.IsNullOrEmpty(amountBox4.Text))
totalBox.Text = (Convert.ToInt32(amountBox1.Text) + Convert.ToInt32(amountBox2.Text) + Convert.ToInt32(amountBox3.Text) + Convert.ToInt32(amountBox4.Text)).ToString();
(TotalBox isEnabled设置为false,因此它是只读的)
现在这以某种方式工作,但不会像我想要的那样更新。 我希望totalbox在valueBox1具有一个值时立即更新,然后在amountBox2具有两个框组合在一起的值时更新,因此第四。
它的操作方式是直到每个框中都有特定内容,直到amountBox4具有值才更新。 我确定您知道这一事实,如果用户仅使用四个中的两个怎么办? 非常感谢帮助
尝试:
var allAmounts = new List<int>();
if (!String.IsNullOrEmpty(amountBox1.Text))
allAmounts.Add(Convert.ToInt32(amountBox1.Text));
if (!String.IsNullOrEmpty(amountBox2.Text))
allAmounts.Add(Convert.ToInt32(amountBox2.Text));
if (!String.IsNullOrEmpty(amountBox3.Text))
allAmounts.Add(Convert.ToInt32(amountBox3.Text));
if (!String.IsNullOrEmpty(amountBox4.Text))
allAmounts.Add(Convert.ToInt32(amountBox4.Text));
totalBox.Text = allAmounts.Sum().ToString();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.