[英]how to tackle with textblock in wp8
here is the code of my text block, 这是我的文本块的代码,
i want to show the difference of two numbers in it, 我想显示其中两个数字的差,
but it gives error, whien i run the app. 但是如果我运行该应用程序,它就会出错。
Error: System.NullReferenceException was unhandled by user code
HResult=-2147467261
Message=Object reference not set to an instance of an object.
here is the code, 这是代码,
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;
how to resolve? 怎么解决?
You can not use textbolck as a string use Text property. 您不能使用textbolck作为字符串使用Text属性。 this will resolve your problem. 这将解决您的问题。
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.