Using RichTextBlock in FlipView in a Metro Style app

I use standard Visual Studio templates, and I have an ItemDetailPage that contains a FlipView with a RichTextBlock in its DataTemplate.

I want to set the RichTextBlock to my custom paragraphs generated in the text. I think there is no way to link the RichTextBlocks block in XAML, so I am using the code behind. In the loaded RichTextBlock event, I set my block, which works fine. But the problem is that the Loaded event is fired only once when the page is displayed. When I “flip” to another element, the selected FlipView element changes, but the Loaded event does not receive the call again (I think this is normal).

I tried setting RichTextBlock on the FlipViews SelectionChanged element, but this does not work.

var ind = this.flipView.SelectedIndex;

        var flipViewItem = this.flipView.ItemContainerGenerator.ContainerFromIndex(flipView.SelectedIndex);

        if (flipViewItem != null)
        {               
            var scroller = FindFirstElementInVisualTree<ScrollViewer>(flipViewItem);
            var tb = scroller.FindDescendantByName("richTextColumns").FindDescendantByName("richTextBlock") as RichTextBlock;
            SetRichContent(tb, (flipView.SelectedItem as ArticleViewModel).HtmlContent);               
        }

SetRichContent is called, sets RichTextBlocks blocks, but they do not visually change, and after several flips, the entire application crashes without any additional information.

So my question is: how can I get my own code called in RichTextBlock with every flip (modified element change)?

+5
source share
1 answer

You can link rich text fields. Make sure your data context is set correctly. We need to see more code to make an appropriate response.

<RichTextColumns>
     <RichTextColumns.ColumnTemplate>
         <DataTemplate>
             <RichTextBlockOverflow Width="400" Margin="50,0,0,0"/>
         </DataTemplate>
    </RichTextColumns.ColumnTemplate>

     <RichTextBlock Width="400">
         <Paragraph>
             <Run Text="{Binding Content}"/>
         </Paragraph>
     </RichTextBlock>
</RichTextColumns>
+1
source

All Articles