Welcome to MSDN Blogs Sign in | Join | Help

Again with the support for simple HTML display in Silverlight [HtmlTextBlock sample updated for Silverlight 2 Beta 2!]

A customer recently asked about an update to my HtmlTextBlock sample for the newly released Silverlight 2 Beta 2. (Background reading: HtmlTextBlock Announcement, Improvements, Beta 1 Update, Data Binding Support) I'd meant to eventually migrate my samples anyway, so HtmlTextBlock seemed like a great place to begin!

HtmlTextBlock Demonstration

I've updated the HtmlTextBlock demonstration page and also the source code download, so you can try things out in your browser and/or download the code to see how it works!

Notes:

  • InitializeFromXaml was removed from Beta 2, so HtmlTextBlock now uses XamlReader.Load to set the equivalent Template in its constructor (and uses OnApplyTemplate to get a reference to the contained TextBlock).
  • Some of the properties HtmlTextBlock used to explicitly expose for TextBlock compatibility have moved to the Control class (from which HtmlTextBlock derives) in Beta 2, so HtmlTextBlock no longer implements them itself (ex: FontFamily, FontSize, Foreground). A handful of TemplateBindings are used to bind these properties of the Template's TextBlock to the corresponding properties on HtmlTextBlock.
  • The parameter list of DependencyProperty.Register changed slightly in Beta 2 and PropertyMetadata is now used to wrap the PropertyChangedCallback parameter.
  • Special-case code for setting certain values of TextBlock.LineHeight is no longer necessary in Beta 2 and has been removed.
  • The unusual "text disappears for certain font/size combinations" behavior that was present in Beta 1 has been fixed by the Silverlight team for Beta 2.

As you might expect, migrating HtmlTextBlock to Beta 2 was fairly straightforward. The majority of the changes arose because it tries to be a TextBlock and some of the text properties shifted around. (Incidentally, I wouldn't expect most applications to bump into this at all.) I hope people find the new sample useful as they come up to speed on Silverlight 2 Beta 2!

Published Wednesday, June 11, 2008 10:14 AM by Delay
Filed under:

Comments

# Silverlight news for June 12, 2008

Thursday, June 12, 2008 5:05 PM by Silverlight news for June 12, 2008

# Smaller is better! [A simple step to shrink the download size of Silverlight 2 applications]

Thursday, July 17, 2008 1:50 AM by Delay's Blog

When putting content on the web, it's important to get that content to the user as quickly as possible.

# My take on simple HTML display in Silverlight [HtmlTextBlock sample updated for Silverlight 2 RTW!]

Wednesday, November 12, 2008 1:17 AM by Delay's Blog

A couple of readers have asked about an update to my long-running HtmlTextBlock sample for Silverlight

# A fix for simple HTML display in Silverlight [HtmlTextBlock bug fix for Silverlight 2 RTW!]

Wednesday, November 12, 2008 6:44 PM by Microsoft Weblogs

I updated my HtmlTextBlock sample for RTW last night and got an email from kind reader Ed Silverton this

Anonymous comments are disabled
 
Page view tracker