簡體   English   中英

自動更新textBox Windows Phone 8 / C#

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM