Archive for July, 2009
Posted on July 9, 2009 - by Adam Elmore
Silverlight 3 Bits
If you haven’t heard, Microsoft has some of the Silverlight 3 bits up on the web. Tommorrow we’ll see an official release. . . get excited!
Here are the downloads:
Expression Blend 3 with Sketchflow
Silverlight 3 Software Development Kit (SDK)
Silverlight 3 Tools for Visual Studio 2008 SP 1
Posted on July 7, 2009 - by Adam Elmore
Silverlight – My Favorite “Web Design” Technology
I was in Barnes & Noble over the weekend, browsing through the technology sections (picked up “Microsoft .NET: Architecting Applications for the Enterprise” by Dino Esposito) when I realized I wasn’t seeing any Silverlight books. I looked through various “programming” categories without any luck. I had decided that this particular small-town BN (Springfield, MO) might have a relatively narrow selection, but I was still shocked to think that they wouldn’t have a single book on the topic. Just as I was primed to ask an employee for assistance, I stumbled into the “Web Design” section of the store where I found a saddening surprise: Silverlight books. In droves. I suppose I should update my job title. . .
Posted on July 2, 2009 - by Adam Elmore
Custom Control Resources
This morning I ran into an interesting bug while working on a custom TabControl created by another member of my team. This TabControl (appropriately named, “TabControl2″) adds a button in the TabPanel for adding new TabItems (among other things). For various reasons, this Button is created dynamically in the class definition and added to the current TabPanel. No problems here until it was time to style the Button in a way that would fit the application. After taking a look at TabControl2.cs, I quickly saw the first mistake:
TabControl2.cs

generic.xaml

AddTabButtonStyle is a DependencyProperty used to update the Style of the dynamically created Button. As you can see, an attempt is made to set the value of this property to the “Local_NewTabButtonStyle” Style. Knowing that the Style defined in generic.xaml is not located within this control’s Resources, I saw a few possible solutions. The obvious solution was to store the Style somewhere within the TabControl2 ControlTemplate. This would give us easy access to the resource in the TabControl2 OnApplyTemplate() method. However, this particular control didn’t have a ControlTemplate defined as it derived directly from TabControl and did not make any changes that warranted a new template (outside of this particular Button). At this point, the smart move would have been to create a default ControlTemplate targeting the TabControl2 control and throw my Button Style directly into the template. Another solution involved creating the Style in C# (no thanks). Turns out, I’m lazy and went with solution number three: move the Local_NewTabButtonStyle resource to App.xaml (that’s right, the application level resources; not so “Local” anymore..), and pull it from Application.Current.Resources.
App.xaml

TabControl2.cs

Aside from the fact that this is very poor design when it comes to creating a custom control, using this “solution” also introduced a very strange bug. I initially ran the application and saw that the style was being applied correctly (after all, the style does reside within the application’s ResourceDictionary). Not feeling the least bit guilty, I moved on to more important tasks (don’t judge me
). An hour later, our team designer hopped on his Mac to take a look at the changes only to find that the application wouldn’t load. I picked up my wife’s MacBook and confirmed the problem: after finishing the Silverlight loading animation, the application loaded a blank white screen. In addition, the browser’s error console was void of any Silverlight exceptions (this problem was occurring in both Firefox and Safari). Strange.
After much toil, I came to the realization that my Application level resource was the culprit. After creating a ControlTemplate for TabControl2 and storing the Style in the root Grid’s resources, I quickly remedied the problem.
generic.xaml

TabControl2.cs

I’d love to hear an explanation for this issue. One thing is for sure – it never rarely pays to take the quick route.
