簡體   English   中英

我可以動態地使文本塊中的文本部分變為粗體嗎?

[英]Can i dynamically make part of text in textblock bold?

例如,我希望綁定到observableCollection的文本塊列表如下所示:

  1. A B C
  2. 纖維

  3. 保利

  4. A B SOR B

  5. EFORE

您可以在C#中使用Flow文檔 ,使用FlowDocument.FontWeight

在此處輸入圖片說明

<FlowDocumentReader>
  <FlowDocument
    FontFamily="Century Gothic"
    FontSize="12"
    FontStretch="UltraExpanded"
    FontStyle="Italic"
    FontWeight="UltraBold"
  >
    <Paragraph>
      Any font settings on this paragraph would override the font settings
      for the FlowDocument.
    </Paragraph>
  </FlowDocument>
</FlowDocumentReader>

FlowDocument flowDoc = new FlowDocument(new Paragraph(new Run("A bit of text content...")));
// Set the desired column gap to 10 device independend pixels.
flowDoc.FontFamily = new FontFamily("Century Gothic");
flowDoc.FontSize = 12.0;
flowDoc.FontStretch = FontStretches.UltraExpanded;
flowDoc.FontStyle = FontStyles.Italic;
flowDoc.FontWeight = FontWeights.UltraBold;

另一種方法是使用運行標簽,如@Gaurang建議:

public SectionExample()
{

    // Create three paragraphs
    Paragraph myParagraph1 = new Paragraph(new Run("Paragraph 1"));
    Paragraph myParagraph2 = new Paragraph(new Run("Paragraph 2"));
    Paragraph myParagraph3 = new Paragraph(new Run("Paragraph 3"));

    // Create a Section and add the three paragraphs to it.
    Section mySection = new Section();
    mySection.Background = Brushes.Red;

    mySection.Blocks.Add(myParagraph1);
    mySection.Blocks.Add(myParagraph2);
    mySection.Blocks.Add(myParagraph3);

    // Create a FlowDocument and add the section to it.
    FlowDocument myFlowDocument = new FlowDocument();
    myFlowDocument.Blocks.Add(mySection);

    this.Content = myFlowDocument;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM