This post is part of a string of posts found here: Learn Blend in a Month.

If you are using multiple instances of elements then it may make more sense to think about making these elements User Controls. User Controls allow you to place objects into a container that can be re-used again and again, even multiple times at once. Every User Control has its own XAML file and its own code file.

To make a selection of elements on stage into a User Control it is really simple. First select all the objects you want to include in your new User Control, then right click anywhere on the selected objects. From the drop down options select ‘Make into UserControl…‘. This creates a new XAML file containing the objects you selected with it’s own code behind file too.

Each time you want to add a new instance of your User Control you will need to add the following XAML in…

<local:UserControlName Margin=”0,0,0,0″/>

This post is part of a string of posts found here: Learn Blend in a Month.

Data Binding allows us to take the value from one object and apply it to another without needing to know a single line of code.

In this tutorial we are going to control the font size of a textBlock through the interaction of a Slider control. To start off we need to draw a Slider control and a textBlock on our stage as seen below.


To dataBind our Sliders value to our textBlocks font size we first need to select the Slider and go to the ‘Properties‘ tab. Scroll down to the ‘Common Properties‘ section and locate the ‘Value‘ property. Click on the small square icon to the right of the field, this will bring up a menu, select ‘Data Binding…‘.

This will bring up the Create Data Binding window. First select the ‘Element Property‘ tab (the middle tab). Now click on the object we want to effect (the textBlock), this will bring up a list of values that can be binded. We want to effect the font size so scroll down and select ‘FontSize‘. Finally we need to make sure the ‘Binding direction‘ is set to ‘TwoWay‘, expand the bottom area to change this setting.

Click ok to save these settings.

Now all that is left to do is to set the minimum and maximum values of our slider, these values will represent the font size range of our textBlock. To change these values go to the ‘Properties‘ tab and scroll down to the ‘Common Properties‘ section. We should end up with the following functionality.


You can see a more complex example of data binding in this previous post of mine.

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.