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. 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;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.