Reputation: 10992
I have a page which renders html content from the database. Now I would like to display this in Silverlight. I thought of either replacing all the tags with silverlight equivalents. Or has someone built something like that already? It seems like the best solution. Anyone else who has any advice?
It would kind of work if there was a way to get hyperlinks to work in silverlight richtextbox control.
<RichTextBox HorizontalAlignment="Left" Margin="25,23,0,0" Name="richTextBox1" VerticalAlignment="Top" Height="251" Width="352" >
<Paragraph FontSize="14" FontWeight="Bold" >Hello</Paragraph>
</RichTextBox>
Like this ain't allowed in Silverlight:
<TextBlock>
Hello <HyperlinkButton > World </HyperlinkButton>
</TextBlock>
I would be forced to do like this:
<StackPanel Orientation="Horizontal">
<TextBlock >
Hello
</TextBlock>
<HyperlinkButton>
World
</HyperlinkButton>
</StackPanel>
Which would be in html like this:
<h3> Hello <a href="#" >World</a></h3>
Sure to some extent the silverlight way would work but converting html-content to xaml seems tedious. If someone has the urge to write a library like this it would be nice.
Upvotes: 2
Views: 607
Reputation: 1214
If HTML is serving you well, why switch to Silverlight? You can certainly convert your HTML into their equivalent tags in XAML but you'll lose you SEO advantage.
If you really want to do that - maybe you find this useful - you still need to reverse engineer a bit :-)
http://msdn.microsoft.com/en-us/library/aa972129.aspx
Upvotes: 0
Reputation: 39277
I have built one of these in the past (for WPF rather than Silverlight). It wasn't easy and it only handles text elements. You should use HtmlAgilityPack to read the HTML and then maintain a stack of the current font state as you process the HTML.
How complex is your HTML?
Upvotes: 1