简体   繁体   English

我可以动态地使文本块中的文本部分变为粗体吗?

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

For example, I want a list of textblock binded to a observableCollection to be like this: 例如,我希望绑定到observableCollection的文本块列表如下所示:

  1. A B C A B C
  2. B CF 纤维

  3. B OY 保利

  4. B OOK

  5. A B SOR B A B SOR B

  6. B EFORE EFORE

You can use Flow document in C#, use FlowDocument.FontWeight 您可以在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;

Another way is to use Run Tag, as @Gaurang recommends: 另一种方法是使用运行标签,如@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