Monday, August 24, 2009

Prime Timetable in Summer Silverlight Coding Competition

I've decided to submit Prime Timetable to the Summer Silverlight Coding Competition hosted by ComponentArt. If you find Prime Timetable interesting, you can vote for it here. In order to vote you will need ComponentArt account (just click on "Log in to cast your vote" > Create account, if you don't have it).
It's my pleasure to be able to take part in this competition. The motivation for entering the coding competition came from these:
  • Not many other Silverlight line of business (LOB) application have been submitted yet, and I wonder why? They don't like to compete or what?
  • I am ambitious by nature and like to compete :).
So, go ahead and vote and may the best Silverlight app win!


Monday, August 17, 2009

Snapshot of scrollable content using Silverlight 3 WriteableBitmap

Recently, I've been working on exporting part of XAML tree to Jpeg image using Silverlight 3 WriteableBitmap and it all went pretty well until I put lots of stuff into exporting content container. Here are some of the problems I've encountered:
  • Scrollbar appears in the snapshot.
  • Non-visible content doesn't appear in the snapshot even when its size increased.
Here is my approach for solving these problems:

1. Prior to creating WriteableBitmap adjust user interface:
  • Adjust the size (width and height) of scrolling content so that the scrollbar doesn't appear.
  • Adjust the size of content containers including plugin size (!), so that you don't have cut offs in exported image.
  • If there are some UIElements you don't want exported, set them as invisible.
2. Create WriteableBitmap.
3. Revert user interface changes.

The part of code that solves scrolling problems in my scenario is published here. Feel free to adjust it to your needs and let me know what you think. I wonder how this could be accomplished in Out Of Browser (OOP) scenario. How can the platform window be resized to get all the scrollable content without cut offs, and does the cut-off problem even exist? I might even try that one day ;).
Example of generating image from (scrollable) content is available online here, just choose Timetable > Export to Jpeg. That's it.


Tuesday, August 11, 2009

JavaScript location.href instead of Silverlight HtmlPage.Window.Navigate

MSDN documentation for Silverlight HtmlPage.Window.Navigate method is pretty basic, here is the link. Summary for the method is: "Opens the specified page in the specified browser instance."
But, behind the scene, if you look at the code in Reflector, HtmlPage.Window.Navigate method invokes JavaScript "open" method. That's all right if you want to call popups, but what if you want to navigate to html page in the same window without calling the popup?
I've encountered following problems with using HtmlPage.Window.Navigate:
  • It looks like there are some problems with the browser's cache when Navigate method is used, as described by Kevin Hazzard here. Furthermore, in case you use Asp.Net postbacks, the popup page can lead to corrupted viewstate in some scenarios.
  • HtmlPage.Window.Navigate method's just stopped working in recent builds of Google Chrome browser, probably because of some internal pop-up blocker code.
Therefore, I've decided to use JavaScript location.href instead of HtmlPage.Window.Navigate when target navigation page is set to "_self". Code snippet which looks like a possible solution is published on Rick Strahl's great CodePaste tool here.



I would like to hear your thoughts and experiences on this.