简体   繁体   中英

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 !

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.

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.

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