D'Arcy from Winnipeg
Solution Architecture, Business & Entrepreneurship, Microsoft, and Adoption

The Evolution of a Silverlight Carousel Control

Tuesday, December 30, 2008 12:12 AM

At DevTeach Montreal earlier this December, Rob Zelt did a fantastic Silverlight presentation where he wowed us by magically switching a boring old list box of planet names into a display of rotating planet images. Rob has a blog post specifically around how he created that demo, and in it he mentions using a carousel control written by Jamie Rodriguez.

Jamie’s example was excellent, but it was written with Silverlight 2 Beta 1. That means that when you open it up, there’s some breaking issues due to the quick evolution of Silverlight. I downloaded Jamie’s code and noticed these changes when I loaded the project up in VS.NET 2008. Doing some searches of the changes I saw brought me to another blog.

Enter Chalvantzis Konstantinos, who took Jamie’s original and upgraded it to Silverlight 2 Beta 2. He outlines some of the changes that I noticed in the code, and also had some people comment on other fixes or ideas of alterations. All good stuff.

However, there are *still* some breaking changes from the Silverlight 2 Beta 2 version of the code to the current Silverlight 2 release. Let me highlight the couple I found, and then talk about my version of the code. You’ll find a link further below to download the code yourself (remember kids: no warranties, guarantees, or promises of any kind).

Aversion to Version
One of the most annoying things with Silverlight is that its VERY picky about which version an application was developed against. Moving up from Silverlight 2 Beta 2 is no different. Trying to run Chal’s code, I was met with a Silverlight download link. Looking at the asp:Silverlight tag in the markup I checked to see if I had it set to the correct markup value, but it was already set to the highest option available…


However, there’s another property available which doesn’t show up in intellisense…


You can manually put in MinimumVersion and specify the very latest version of the Silverlight2. All I did to find this was to create a new Silverlight project and grab the MinimumVersion value from the auto-generated aspx test page (VS.NET 2008 will automatically use the MinimumVersion property and not Version).

Handled is Out
One line of code that broke was in the MouseLeave event, where it checks who the sender is and sets the MouseEventArg’s Handled property accordingly. But OH NOES: there *is* no Handled property for that object anymore in Silverlight 2. I need to do a bit more digging as to why this was taken out, but for a glimpse of the argument from both sides check out this forum thread from the Silverlight forums.

Height Matters
This isn’t really a versioning issue…more of a development observation. The carousel displays images spinning around, but I had one version of the control that just wouldn’t display the images until I altered the height of the harness. It had to be tall enough to display the images or else they wouldn’t load (I guess I was assuming that it would just magically start moving the images even though the height was off). Something to keep in mind with Silverlight dev if you’re not getting the output you expect: might just be a height/width issue.

The Code
So those were the only three things that really stood out beyond what Chal had fixed in his version. My version of the code has a few changes. I created a separate library project to hold the carousel control class as well as the harness class. This makes the control reusable across multiple applications. The one thing that still needs to be part of the xaml is the markup for the control though.

I’ve got a few other ideas of things to improve on. One thing is to make the settings for the harness configuration based. I also want to try and add a pop-out window when you click on an image (the reason I’m working on this control is because I want to have a sponsorship component for our code camp site…hence why my project is called SponsorshipBanner).

Grab the code and let me know if you have any other ideas that we could throw into this thing…maybe make it a Codeplex project?


No comments posted yet.

Post a comment