简体   繁体   English

自动更新textBox Windows Phone 8 / C#

[英]automatically update textBox windows phone 8/C#

wassup guys i did a search and found a couple of post they helped out but for some reason it isnt working completely wassup伙计们,我进行了搜索,发现了几则帖子,他们帮了忙,但由于某种原因,它无法完全正常工作

ok here is my code: 好的,这是我的代码:

 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 is set to false so it becomes read only) (TotalBox isEnabled设置为false,因此它是只读的)

now this in a way works but it doesn't update like i want. 现在这以某种方式工作,但不会像我想要的那样更新。 I would like totalbox to update as soon as amountBox1 has a value and then when amountBox2 has a value to update with the two boxes combined and so fourth. 我希望totalbox在valueBox1具有一个值时立即更新,然后在amountBox2具有两个框组合在一起的值时更新,因此第四。

the way its doing it is it wont update until there is something in each box specifically until amountBox4 has a value. 它的操作方式是直到每个框中都有特定内容,直到amountBox4具有值才更新。 Im sure your aware of the fact, what if the user only use two out of the four? 我确定您知道这一事实,如果用户仅使用四个中的两个怎么办? help is much appreciated 非常感谢帮助

Try: 尝试:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM