0

I have some string like "Some tmp string with text " or "Some tmp string with text" or with other Html format.

The Requirement is to show this text with the same format in RichTextBlock.

To do this, I tried to make some thing like this:

   <RichTextBlock x:Name="rtb">
            <Paragraph x:Name="par">
                <Run FontStyle="Italic"
                     FontWeight="Bold">
                    Some tmp text
                </Run>
            </Paragraph>            
        </RichTextBlock>

But it formats all the text in Run element, but not the : "Some tmp string with text "

I tried to make Run elements programmatically and add them to paragraph, but have the same problem.

Any suggestions?

DivyaMaheswaran
  • 886
  • 1
  • 12
  • 16
  • Take a look at this Nuget Package: https://github.com/VincentH-Net/WinRT-RichTextBlock.Html2Xaml – Martino Bordin Sep 12 '17 at 15:41
  • thanks, now i am reading about it – Perceptron Sep 12 '17 at 19:09
  • ok let me know if you need additional help. – Martino Bordin Sep 12 '17 at 20:18
  • Sorry, but how correct implement it to project (i work with UWP): 1. I copied files to the folder(Common) 2. Implement in namespace in my MainPage xmlns:common="using:WinRT_RichTextBlock.Html2Xaml.Common"> 3.But when use It go to mistake, that there is no any Properties.Html – Perceptron Sep 13 '17 at 07:38
  • now all ok, entredString - some string like "Some tmp string" but HtmlChanged doesnt work – Perceptron Sep 13 '17 at 08:19
  • all work, but **stream** null – Perceptron Sep 13 '17 at 10:40
  • // Read XSLT. In design mode we cannot access the xslt from the file system (with Build Action = Content), // so we use it as an embedded resource instead: Assembly assembly = typeof(Properties).GetTypeInfo().Assembly; using (Stream **stream** = assembly.GetManifestResourceStream("WinRT_RichTextBlock.Html2Xaml.RichTextBlockHtml2Xaml.xslt")) { StreamReader reader = new StreamReader(stream); – Perceptron Sep 13 '17 at 10:40
  • that always call exception – Perceptron Sep 13 '17 at 10:41
  • It's because the resources has a different name since it's in your assembly and with a different namespace. Call Assembly.GetManifestResourceNames () to see a list of the embedded resources and pass the right name when calling: ssembly.GetManifestResourceStream(**"PutYourResourceNameHere"**) – Martino Bordin Sep 13 '17 at 10:43
  • thanks, now will try – Perceptron Sep 13 '17 at 10:51
  • I make RichTextBlock Html2Haml.xslt like **embedded resource** , and changed ssembly.GetManifestResourceStream("PutYourResourceNameHere"), all work - thank you. But it just split my input text by html tegs, with out formating text by html tags – Perceptron Sep 13 '17 at 13:52
  • I will try more, thank you for help – Perceptron Sep 13 '17 at 13:54

0 Answers0