繁体   English   中英

c#wpf上标(不在XAML中)

[英]c# wpf superscript (not in XAML)

我有一个问题要问你。 如何仅使用C#在文本块中制作上标? 我的目标是动态转换字符串(“ ^”号的计数会动态更改),因此无法在XAML中编写它(否则我不知道如何做)。 我尝试了此链接中的代码-WPF中的上标 但这不起作用:(

谢谢!

我找到答案了! 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);

暂无
暂无

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

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