自动更新文本框windows phone 8/C#

自动更新文本框windows phone 8/C#,c#,windows-phone-8,C#,Windows Phone 8,wassup的家伙们,我搜索了一下,找到了一些他们帮助的帖子,但由于某些原因,它并没有完全起作用 好的,这是我的代码: if (!string.IsNullOrEmpty(amountBox1.Text) && !string.IsNullOrEmpty(amountBox2.Text) && !string.IsNullOrEmpty(amountBox3.Text) && !string.IsNullOrEmpty(amountB

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在amountBox1有一个值时立即更新,然后在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();
var allAmounts=newlist();
如果(!String.IsNullOrEmpty(amountBox1.Text))
allAmounts.Add(Convert.ToInt32(amountBox1.Text));
如果(!String.IsNullOrEmpty(amountBox2.Text))
allAmounts.Add(Convert.ToInt32(amountBox2.Text));
如果(!String.IsNullOrEmpty(amountBox3.Text))
allAmounts.Add(Convert.ToInt32(amountBox3.Text));
如果(!String.IsNullOrEmpty(amountBox4.Text))
allAmounts.Add(Convert.ToInt32(amountBox4.Text));
totalBox.Text=allAmounts.Sum().ToString();

您使用的是ViewModel还是直接在代码隐藏中工作?我在这一次使用的是代码隐藏,因为我在这个应用程序中只使用了4个文本框。在这个应用程序中,我是否仍然使用文本更改事件?如果是,我是否在每个文本框下使用代码?是的,但您不需要复制事件处理程序。创建一个文本框,并将所有“文本更改”事件指向该文本框。谢谢您,先生,这很有效,非常感谢您为我的学习添加内容!