The complete Silverlight Live Comment Preview series of posts:
I've learned a thing or two since the initial post about my Silverlight Live Comment Preview control, including how to use all of the WPF colors in Silverlight, how to set initial parameters and use the <object> tag, and how to allow for better customization of all sorts of attributes like fonts and colors. I'd already leveraged much of this newfound knowledge by fixing up my Silverlight Tag Cloud control, so I thought it a good time to revisit my Live Comment control and touch it up a bit as well.
Some of the biggest problems with that first implementation was that if you wanted to change things like font family, font color, font size, the background color, or even the initial text to display upon initialization (you might need to display some initial text on a postback if processing a failed captcha, for example), you had to make those changes in the Silverlight control itself, recompile, and deploy the new control. What a pain… Not to mention the control did not auto-size with respect to its container width.
The New and Improved Silverlight Live Comment Preview Control
I implemented all of those features and even wrapped the control in an ASP.NET User Control to boot. Now, to use the control, you start with a Register declaration:
1: <%@ Register src="~/UserControls/LiveCommentPreview.ascx" TagName="LiveCommentPreview" TagPrefix="sl" %>
Then declare the control like this:
1: <sl:LiveCommentPreview runat="server" BackgroundColor="AliceBlue" FontColor="Orange"
2: FontFamily="Tahoma" FontSize="14" InitialPreviewText="Initial [b]formatted[/b] text." />
For BackgroundColor and FontColor, you can use any of the available WPF color names. FontFamily and FontSize are what you might expect. Last, InitialPreviewText is the initial text you want rendered in the control. In general, you can exclude this parameter, but there are cases where I found it useful. The most notable was if someone failed a recaptcha, then on the postback, and since the comment box still contained the user's comment, then the Live Comment Preview control should already contain that same text (but formatted, of course).
Last, the control's width now auto-sizes. See it in action by going to any post on this blog (say, this one, for example), scroll down to the bottom, and adjust the browser width. You can also see it in action by downloading the source code and running the included web site.
Here's the control set into the context of this web site:
Silverlight Live Comment Preview Control: Now on CodePlex
The Silverlight Live Comment Preview control is now available for download on CodePlex.
Full source, example usage, etc. are available there. Licensing is such that you can do whatever you like with the control, except you'll need to leave the attribution in place (or, rather, I'd appreciate you leaving it in place ;-) ).
Good luck and have fun. Of course, any ideas for new functionality or if you have problems, leave a comment here or on the CodePlex project page.
Download: Silverlight Live Comment Preview Control on CodePlex