繁体   English   中英

如何使用 WPF 和 c# 以编程方式在文本块中添加多个属性?

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

如何使用 c# 代码向 WPF 中的文本块中的特定文本添加多个属性,在本例中为ForegroundFontSize

我试过像下面那样做,但出现错误

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 });

帮助 !

有一件事是语法错误

代替

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

你必须使用

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

每当您询问时,您还应该描述错误消息本身。 我不知道这是您的复制/粘贴错误还是您遇到的真正问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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