一個RichTextBox我有一組文字,我想放一個RichTextBox肚裏像這樣:標+下劃線內嵌在WPF
所以我用一個RichTextBox,因爲它允許我做以下事情。然而
var zipCodeParagraph = new Paragraph();
string zipCodes = String.Empty;
var dateRun = new Underline(new Run(DateTime.Today.DayOfWeek + ", " + CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(DateTime.Today.Month) + ' ' + DateTime.Today.Day));
Underline dateSuperscript;
switch (DateTime.Today.Day % 10)
{
case 1:
dateSuperscript = new Underline(new Run("st"));
break;
case 2:
dateSuperscript = new Underline(new Run("nd"));
break;
case 3:
dateSuperscript = new Underline(new Run("rd"));
break;
default:
dateSuperscript = new Underline(new Run("th"));
break;
}
dateSuperscript.BaselineAlignment = BaselineAlignment.Superscript;
if (ZipCodes.Any())
{
zipCodeParagraph.Inlines.Add(new Run("The following zip codes are facing a "));
zipCodeParagraph.Inlines.Add(new Underline(new Run("Severe Weather Threat")));
zipCodeParagraph.Inlines.Add(new Run(" on "));
zipCodeParagraph.Inlines.Add(dateRun);
zipCodeParagraph.Inlines.Add(dateSuperscript);
zipCodes = String.Join(", ", ZipCodes.ToArray());
}
的結果是,像這樣:
的問題是,改變文本的基線時要標/下標,然後到高度下劃線也會改變。我希望下劃線保持在原來的位置,並且還要發生超級腳本。
我發現只有一個關閉的解決方案,它不會以編程方式執行它here。
工作正常!非常感謝你! :) – AzzamAziz