October 27th, 2009
Using Resources to share styling in Blend
Silverlight Blend Tutorials, Working with Silverlight, by Gavin Wignall.This post is part of a string of posts found here: Learn Blend in a Month.
When styling up a control, Expression Blend allows you to apply that style to other controls. This firstly allows file sizes to be kept down as the style is only written in the XAML once. Secondly this allows you to retain consistency across multiple controls set to the same style, when making changes to one, all controls set to that style will update automatically.
Below is an example of four standard button controls.
Now I am going to apply a visual style to the first button. You can read more about applying a style to the button control in this previous post. See how our first button is now visually unique compared to the other three.
Now to apply the same style to the following three buttons is really easy. To apply a style, we right click the button we want to change and select ‘Edit Template‘ and then ‘Apply Resource‘. We now see a list to choose from of styles we have created that are available for that control.
We can repeat this process to each of the buttons to apply this style to all four buttons.
Notice that the style applies to the contents inside the control. The Button control has a ‘Content Presenter‘ inside the control that uses Data Binding (we will touch on Data Binding later in this tutorial series) to pull through the text content, styling and color from the controls top level. By keeping this ‘Content Presenter‘ inside the styling we can keep the text on each button unique.
We can also make our style unrestricted to a fixed size, this allows us to use the same style for different sized buttons as shown below.
Styles can be applied to all control inside Silverlight.
[...] This post was mentioned on Twitter by Silverlight News, Ken Azuma and Brent Gunter, AJDev.net. AJDev.net said: RT @SilverlightNews: Using Resources to share styling in Blend – http://snurl.com/suilx [...]
[...] Using Resources to share styling in Blend [...]