【问题标题】:c# wpf superscript (not in XAML)c# wpf 上标(不在 XAML 中)
【发布时间】:2016-02-10 18:22:45
【问题描述】:

我有一个问题要问你。如何仅使用 c# 在文本块中制作上标? 我的目标是动态转换字符串('^' 符号的计数是动态改变的),所以不可能用 XAML 编写它(或者我不知道该怎么做)。 我尝试了此链接中的代码 - Superscript of superscript in WPF。但它不起作用:(

谢谢!

【问题讨论】:

  • 我认为您需要富文本块
  • 那么它会是什么样子?
  • 我认为你真正想要的是渲染Markdown
  • 这也是个好主意:)

标签: c# wpf superscript


【解决方案1】:

我找到了答案! TextBlock 可以这样动态改变:

Run run1 = new Run("This is ");

Run run2 = new Run("bold");
run2.FontWeight = FontWeights.Bold;

Run run3 = new Run(" and ");

Run run4 = new Run("italic");
run4.FontStyle = FontStyles.Italic;

Run run5 = new Run("text.");

Run run6 = new Run("x");

Run run7 = new Run("2");
run7.BaselineAlignment = BaselineAlignment.Subscript;

myTextBlock.Inlines.Add(run1);
myTextBlock.Inlines.Add(run2);
myTextBlock.Inlines.Add(run3);
myTextBlock.Inlines.Add(run4);
myTextBlock.Inlines.Add(run5);
myTextBlock.Inlines.Add(run6);
myTextBlock.Inlines.Add(run7);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多