繁体   English   中英

如何处理WP8中的文本块

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

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