Tweaking The Default Styles For Silverlight 2 Controls

April 1 2008

In WPF, when styling a control, Blend has a very handy feature which allows you to get at the default style and template for any control, simply by right clicking the control and selecting "Edit Control Parts (Template)" and then selecting "Edit a Copy..."  These styles and control templates are great places to start when restyling controls.

Unfortunately, Silverlight 2 doesn't have the corrallary in Blend (yet).  However, this is easy to get around once you get a hold of the generic.xaml file for all the Silverlight controls. I went ahead and posted it, although there are two other places you can get an "official" copy. First is the source code for the Silverlight Controls themselves.  Second is by using Reflector, loading C:\Program Files\Microsoft SDKs\Silverlight\v2.0\Libraries\Client\System.Windows.Controls.dll and looking at its resources in the disassembler.

Once you have generic.xaml, restyling controls by tweaking the existing styles is simple.  First, cut/paste the contents of generic.xaml (either all the styles or just the style of the control you want to restyle) into the resources of either app.xaml or one of your pages (depending on the scope you are seeking.) Second, give the style an x:Key value so that you can reference it later. Finally, add that style attribute to your control in XAML: Style="{StaticResource CustomButton}".  That's it!  Now you can tweak the style of the button, even changing the storyboards that get fired as a result of different states.

Comments (17) -

3/29/2008 8:43:00 AM #

blogs.msdn.com/.../...available-via-clickonce.aspx">This</a> is useful too.
          

Josh Santangelo

3/31/2008 8:08:00 PM #

>>Style="{StaticResource CustomButton}

I don't want to define "Style" to control. It would be great if the style is able to overide the exiting based on the scope..

For example:

In generic.xaml, there is a style like below for DataGrid.

<Style TargetType="localLaughingataGrid" x:Key="myDataGridStyle">

I copied this style and pasted in App.xaml in my project.
then, I change some color in that style..

When I run the application, Datagrid is not using the style from App.xaml of my project but generic.xaml from original project. Frown

Yes. Of course, If I give x:Key and use it in Datagrid, it will work but this is not the way that I want.
          

Michael Sync

4/1/2008 1:08:00 AM #

>>Style="{StaticResource CustomButton}

I don't want to define "Style" to control. It would be great if the style is able to overide the exiting based on the scope..

For example:

In generic.xaml, there is a style like below for DataGrid.

<Style TargetType="localLaughingataGrid" x:Key="myDataGridStyle">

I copied this style and pasted in App.xaml in my project.
then, I change some color in that style..

When I run the application, Datagrid is not using the style from App.xaml of my project but generic.xaml from original project. Frown

Yes. Of course, If I give x:Key and use it in Datagrid, it will work but this is not the way that I want.
          

Michael Sync

4/5/2008 5:25:00 AM #

Check out this post by Jaime on default styles: blogs.msdn.com/.../...tyling-and-generic-xaml.aspx" target="_blank" >blogs.msdn.com/.../...tyling-and-generic-xaml.aspx
          

Karsten Januszewski

2/20/2011 4:42:12 PM #

Jordans for Cheap

Good post. I like it very much. thank you! <a href="http://www.nikejordans.net/">; Jordans for Cheap</a>

Jordans for Cheap

2/20/2011 4:42:26 PM #

Jordans for Cheap

Good post. I like it very much. thank you! <a href="http://www.nikejordans.net/">; Jordans for Cheap</a>

Jordans for Cheap

4/11/2011 6:01:46 PM #

Cheap Max Shoes

You may not be ready to control the instances, but you are able to compose your response. It is possible to turn your ache into profanity -or into poetry. The selection is up to you. You may well not have selected your challenging time, but you'll be able to choose how you'll react to it.

Cheap Max Shoes

4/21/2011 6:02:44 PM #

GHD Straightener Outlet

You will discover hundreds of millions exactly who imagine this Messiah possesses are available. In the event he / she performed, subsequently it truly is sad to say the way it is of which his or her brave giving up in addition to demise have gotten not any consequence at all within the incredibly dilemma his or her forthcoming might have been required to target, intended for heritage proves, further than dilemma, that any of us Christians are as risky, singly in addition to en masse, seeing that non-Christians.

GHD Straightener Outlet

6/1/2012 12:41:00 AM #

new era mlb hats wholesale

Your Blog is very good, I like it! Thank you for you sharing!Your blog is really helps for my search and i really like it.

new era mlb hats wholesale

6/1/2012 12:41:14 AM #

new era mlb hats wholesale

Your Blog is very good, I like it! Thank you for you sharing!Your blog is really helps for my search and i really like it.

new era mlb hats wholesale

6/1/2012 12:41:30 AM #

new era mlb hats wholesale

Your Blog is very good, I like it! Thank you for you sharing!Your blog is really helps for my search and i really like it.

new era mlb hats wholesale

7/30/2012 4:53:17 PM #

cheap supreme hats

Nice blog,keep it up    
Will come back soon.
Thanks for sharing .

cheap supreme hats

8/13/2012 1:32:38 AM #

lichen planus cause

Thanks for taking this opportunity to discuss this, I appreciate with this and if you have some more information please share it with me

lichen planus cause

8/13/2012 1:33:03 AM #

lichen planus cause

Thanks for taking this opportunity to discuss this, I appreciate with this and if you have some more information please share it with me

lichen planus cause

8/13/2012 1:33:34 AM #

lichen planus cause

Thanks for taking this opportunity to discuss this, I appreciate with this and if you have some more information please share it with me

lichen planus cause

8/31/2012 3:58:55 AM #

wesley gibson jacket

Thanks for sharing this post.

wesley gibson jacket

8/31/2012 3:59:17 AM #

wesley gibson jacket

Thanks for sharing this post.

wesley gibson jacket

Add comment

biuquote
  • Comment
  • Preview
Loading

VSAchievements
Visual Studio Achievements
Karsten Januszewski (207 Points)
Welcome To The Rhizohm | All posts tagged 'Windows-Phone-7'

Sorry, no posts matched your criteria

VSAchievements
Visual Studio Achievements
Karsten Januszewski (207 Points)