Domanda

I load the data from the network, and then using the library Html2Xaml generating XAML from the resulting HTML file and binds the resulting string to RichTextBlock.DataContext, but when you open the page is blank, what am I doing wrong?

<ScrollViewer VerticalScrollBarVisibility="Auto">
    <RichTextBlock>
       <RichTextBlock.DataContext>
            {Binding Content}
       </RichTextBlock.DataContext>
    </RichTextBlock>
</ScrollViewer>

Content getting so variable:

var item = await SampleDataSource.GetItemAsync((String)e.NavigationParameter);
HtmlDocument link_page = new HtmlDocument();
link_page.LoadHtml(await LoadPage(item.UniqueId));
HtmlNode _table2 = link_page.GetElementbyId("main_body");
item.Content = Html2XamlConverter.Convert2Xaml(_table2.WriteContentTo());
//Content now looks like this: "<Paragraph LineStackingStrategy="MaxHeight">Процедурная генерация карты (часть 1)</Paragraph><Paragraph  LineStackingStrategy="MaxHeight"></Paragraph><Paragraph  LineStackingStrategy="MaxHeight">Автор: <Bold>Артем Гуревич</Bold></Paragraph><Paragraph  LineStackingStrategy="MaxHeight">..."
this.DefaultViewModel["Item"] = item;
È stato utile?

Soluzione

If your HTMLToXaml conversion logic is working, and if your DataContext is set correctly, then the problem would be that you're not affecting the text to your RichTextBox, setting the DataContext is not enough, you should do :

<ScrollViewer VerticalScrollBarVisibility="Auto">
    <RichTextBlock>
       <RichTextBlock.DataContext>
            {Binding Content}
       </RichTextBlock.DataContext>
       <FlowDocument>
            <Paragraph>
                <!--your content should be here-->
            </Paragraph>
       </FlowDocument>
    </RichTextBlock>
</ScrollViewer>

You can put many Paragraphs as you wish, they just need to be inside a FlowDocument, hence you should extract each paragraph's value from the item.Content and add it as a paragraph to the FlowDocument :

        Paragraph myParagraph = new Paragraph();
        myParagraph.Inlines.Add(ParagraphValueFromItemContent);

        // Add the paragraph to the FlowDocument.
        myFlowDoc.Blocks.Add(myParagraph);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top