Click here to Skip to main content
15,882,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi All,

I am a newbie to WPF. I am working on the usercontrols in WPF where in I have a TextBlock in usercontrol.

I have a formatted string coming from my web service in the following format.
XML
This is <Bold>Sample</Bold>, <Italic>Text</Italic> 


I need to set this text to the TextBlock of my user control.

When I set it like this, the output on the wpf screen comes as expected.
XML
<TextBlock Height="181" HorizontalAlignment="Left" Margin="71,33,0,0" Name="textBlock1" VerticalAlignment="Top" Width="316">
            Test with <Bold>bold</Bold>, <Italic>italic</Italic> and
       </TextBlock>


How do I set the inline text of a TextBlock by code behind?

Thanks in advance.

"Happy Coding"
Posted
Comments
Gopi Kishan Mariyala 15-Jan-14 1:26am    
Can you look at the below link
http://www.codeproject.com/Articles/234651/Basic-HTML-Markup-in-WPF-TextBlock

pls read this link http://msdn.microsoft.com/en-us/library/system.windows.controls.textblock(v=vs.110).aspx[^]


sample:
C#
textBlock1.Inlines.Add(new Bold(new Run("bold")));
............
textBlock1.Inlines.Add(new Italic(new Run("italic")));
 
Share this answer
 
Refer - Basic HTML Markup in WPF TextBlock[^].

It suggests to use...
C#
textBlock.Inlines.AddRange(SierraLib.UI.WPF.Text.MarkupProcessor.HTMLtoWPF("<b><u><i>Show me some text!</i></u></b>"));

So, you need to replace the <Bold> with <b> and <Italic> to <i> before this code.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900