Dim
Dim

Reputation: 4837

Insert HTML tags in TextBlock

I have small problem

This works fine and I see the tags:

 <TextBlock TextWrapping="Wrap" Name="RTBOX">
           Hello <Bold>my</Bold> faithful <LineBreak/> sdfsdf <Underline>computer</Underline>.<Italic>You rock!</Italic>
  </TextBlock>

But this does not, and I see all tags as text:

RTBOX.Text = " Hello <Bold>my</Bold> faithful <LineBreak/> sdfsdf <Underline>computer</Underline>.<Italic>You rock!</Italic>";

Upvotes: 0

Views: 204

Answers (1)

Heena
Heena

Reputation: 8654

In c# you can achieve using Inline and Run

        RTBOX.Inlines.Add("hello ");
        Run run = new Run("my ");         
        run.FontWeight = FontWeights.Bold;
        Run run1 = new Run("faithfull\n ");
        Run run2 = new Run("sdsf ");
        Run run3 = new Run("Computer");           
        run3.TextDecorations = TextDecorations.Underline;

        Run run4 = new Run(" You rock !");
        run4.FontStyle = FontStyles.Italic;

        RTBOX.Inlines.Add(run);
        RTBOX.Inlines.Add(run1);
        RTBOX.Inlines.Add(run2);
        RTBOX.Inlines.Add(run3);
        RTBOX.Inlines.Add(run4);

Result

enter image description here

Upvotes: 1

Related Questions