0

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;
4

1 回答 1

0

如果您的 HTMLToXaml 转换逻辑正常工作,并且您的 DataContext 设置正确,那么问题将是您没有影响 RichTextBox 的文本,设置 DataContext 是不够的,您应该这样做:

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

您可以根据需要放置许多段落,它们只需要在 a 内FlowDocument,因此您应该从 item.Content 中提取每个段落的值并将其作为段落添加到 FlowDocument :

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

        // Add the paragraph to the FlowDocument.
        myFlowDoc.Blocks.Add(myParagraph);
于 2014-02-11T10:05:24.243 回答