.NET Blog

Tony Cavaliere

  And the Grappa wins.
E-mail me Send mail
Add to Technorati Favorites AddThis Feed Button

Subscribe to Cynot Why Not


Disclaimer

Hey unlike other bloggers I stand by what I say but just in case. The opinions expressed herein are my own except on Tuesday when the second card is not turned up otherwise it ain't worth squat.

© Copyright 2009

Silverlight: Finding the default style

One of the things I like about Silverlight is the ability to customize existing controls. Just about every control that ships with Silverlight has a default style. You are free to override the default style, create a new style from scratch or if you so choose edit a copy of the default style. Using the new style is as simple as setting the Style attribute  Style="{StaticResource StyleName} where StyleName is the name of the style. For further information on styling refer to the following post.

But where can you find the default style for a control?

Excluding third party tools, I know of at least three ways;

1. From the Silverlight Documentation

If you haven't done so then download the offline Silverlight documentation. The default styles for the Silverlight controls are published in this document.

SL Doco Button Style

2. Use Blend

The second way is to use blend. All you need to do is select the control and right click and choose Edit Control Parts (Template)->Edit Copy. This will create a copy of the default style and attach it the control.

blend button style

3. .NET Reflector (Before you begin I realize this is a third party tool, but it's my blog and I use it so much it doesn't feel like one anymore)

The final method is to use everybody's friend, .NET Reflector. Find the assembly for the control. For example, if you are wanting the default style for say a button then add the following assembly to .NET reflector.

C:\Program Files\Microsoft SDKs\Silverlight\v2.0\Reference Assemblies\System.Windows.dll

Next navigate to the Systems.Windows->Resource->System.Windows.g.resources node and double click it. After doing so you .NET Reflector will appear similar to the the following

NET reflector style

Next double click the XAML file in the disassembler pane. Provider you have associated the XAML file extension with the VS2008 executable you should see the default styles for all the controls in that assembly, similar to the figure below. Note the default file association for XAML is IE which does not render the XAML correctly.

VS2008 XAML

Which method do I prefer? The first will only work with the documentation and the code are in sync. Both Blend and Reflector will produce styles that are in sync with the code, however, Blend is not free and not every developer will have a copy. Need I say more.

Guess the movie

Seventeen *days?* Hey man, I don't wanna rain on your parade, but we're not gonna last seventeen *hours!* Those things are gonna come in here just like they did before. And they're gonna come in here...

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Categories: Silverlight
Posted by CynotWhyNot on Saturday, November 15, 2008 5:57 PM
Permalink | Comments (5) | Post RSSRSS comment feed

Related posts

Comments

Rocky Moore us

Sunday, November 16, 2008 3:12 AM

Rocky Moore

I keep hopying Microsoft will add most of Blend's ability to VS like they did with Expression Web. From the sounds of all the new they are supposedly adding to Blend this next year, I figure integration with VS will be another version beyond the 2010 issue.

Guess the movie:

Aliens maybe?

Tony Cavaliere us

Tuesday, November 18, 2008 4:09 PM

Tony Cavaliere

I just read scottgu's posting and it sounds like blend within VS is coming soon. Great news!

Aliens is the movie. Congrats!

Rocky Moore us

Tuesday, November 18, 2008 6:57 PM

Rocky Moore

Thanks for the notice! How cool is that! Hard to wait until next year now, oh well a lot to learn with SL2 anyway ;)

Busby SEO Test us

Monday, January 19, 2009 11:59 PM

Busby SEO Test

Hellow, nice blog, tnx for the information......nice idea

Perfect Home Design us

Thursday, March 12, 2009 7:25 AM

Perfect Home Design

im looking that before

Add comment


(Will show your Gravatar icon)  

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

Saturday, July 04, 2009 9:03 AM