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)?
source
share