[英]how to tackle with textblock in wp8
這是我的文本塊的代碼,
我想顯示其中兩個數字的差,
但是如果我運行該應用程序,它就會出錯。
Error: System.NullReferenceException was unhandled by user code
HResult=-2147467261
Message=Object reference not set to an instance of an object.
這是代碼,
TextBlock diffBlock = new TextBlock();
diffBlock.FontSize = 30;
diffBlock.Text = " ";
diffBlock.Text = (total - double.Parse(income.Inc)).ToString();
ContentPanel.Children.Add(diffBlock);
Difference.Foreground = new SolidColorBrush(Colors.Black);
Difference.Text = "Remaining Budget: " + diffBlock;
怎么解決?
您不能使用textbolck作為字符串使用Text屬性。 這將解決您的問題。
TextBlock diffBlock = new TextBlock();
diffBlock.FontSize = 30;
diffBlock.Text = " ";
if(income!=null)
diffBlock.Text = (total - double.Parse(income.Inc)).ToString();
else
diffBlock.Text = total.ToString();
ContentPanel.Children.Add(diffBlock);
Difference.Foreground = new SolidColorBrush(Colors.Black);
Difference.Text = "Remaining Budget: " + diffBlock.Text;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.