Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to add multiple properties in a Textblock programatically using WPF & c#?

How do I add multiple properties, in this case Foreground & FontSize to a particular text in a textblock in WPF using c# code ?

I’ve tried doing it like below but getting error

mytxtblock.Inlines.Clear();
mytxtblock.Inlines.Add(new Run("Bills pending for Processing: ") { Foreground = Brushes.Aquamarine });
mytxtblock.Inlines.Add(new Run(pendingBills.ToString()) { Foreground = Brushes.LimeGreen } { FontSize = 13 });

Help !

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

There is one thing that is a syntax error

Instead of

mytxtblock.Inlines.Add(
  new Run(pendingBills.ToString()) 
  { 
    Foreground = Brushes.LimeGreen 
  } 
  { 
    FontSize = 13 
  });

you have to use

mytxtblock.Inlines.Add(
  new Run(pendingBills.ToString()) 
  { 
    Foreground = Brushes.LimeGreen, 
    FontSize = 13 
  });

Whenever you ask, you should also describe the error message itself. I do not know if that is a copy/paste error from you or the real problem you have.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading