locked
Binding XAML content in code-behind to RichTextColumn content

    Question

  • Rather than do the following:

    <common:RichTextColumns x:Name="richTextColumns" Margin="25,20,25,20">
    
    <RichTextBlock  x:Name="richTextBlock" Width="300" Height="500" Foreground="Black" IsTextSelectionEnabled="False" FontSize="14">
    
     <Paragraph>
       <Run  Foreground="Black" Text="{Binding Content}" />
     </Paragraph>
    
    </RichTextBlock>

    Which displays the text in the columns but without any formatting, how can I set the content of the rich text block so that it has the formatting driven from the files (set in a binding or code behind) so that the column flow of Rich Text Columns is maintained as well as the document formatting.

    Does anyone have a good example of a XAML formatted document for Rich Text Block that can be used as a good test case?

    So in summary:

    - how do I set formatted text in RichTextBlock or RichTextColumns that maintains the formatting and column flow?

    Thanks,

    Bryan

    Thursday, February 20, 2014 4:39 PM

Answers

  • Thank you for the information. Although it did not answer the problem it did put me in a great direction and I changed it to the following solution:

    http://amrreda.wordpress.com/2013/12/15/windows-8-1-mvvm-binding-to-richtextblock/

    This shows how to bind a RichTextBlock with content at run-time using a Dependency Object.

    Much appreciated for your time. It put me on the right direction!

    • Marked as answer by zar.net Friday, February 21, 2014 4:23 PM
    Friday, February 21, 2014 4:23 PM

All replies

  • Hi Bryan,

    Not sure what the RichTextColumns is, seems not to be the default windows store app control.

    However I found an interesting blog: Displaying HTML Content in a RichTextBlock, RichTextBlock can display whatever you want if you write the code for it, the sample is for HTML, kind of formatted text.

    RichTextBlock provides more advanced formatting features than the TextBlock control. You can apply character and paragraph formatting to the text in the RichTextBlock. For example, you can apply Bold, Italic, and Underline to any portion of the text in the control. The content property of RichTextBlock is the Blocks property, which is based on the Paragraph element. You can use the RichTextBlock to display text with UI elements that are derived from UIElement, such as images. You can do this by using the InlineUIContainer.

    Also take a look at the sample:  XAML text display sample.

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.


    Friday, February 21, 2014 2:00 AM
    Moderator
  • Thank you for the information. Although it did not answer the problem it did put me in a great direction and I changed it to the following solution:

    http://amrreda.wordpress.com/2013/12/15/windows-8-1-mvvm-binding-to-richtextblock/

    This shows how to bind a RichTextBlock with content at run-time using a Dependency Object.

    Much appreciated for your time. It put me on the right direction!

    • Marked as answer by zar.net Friday, February 21, 2014 4:23 PM
    Friday, February 21, 2014 4:23 PM