Understanding Expression Blend and How to Use it with Silverlight 4

Exclusive offer: get 50% off this eBook here
Microsoft Silverlight 4 Business Application Development: Beginner’s Guide

Microsoft Silverlight 4 Business Application Development: Beginner’s Guide — Save 50%

Build enterprise-ready business applications with Microsoft Silverlight 4 with this book and eBook

£20.99    £10.50
by Frank LaVigne | April 2010 | Beginner's Guides Microsoft Web Development Web Graphics & Video

In this article by Frank LaVigne, author of Microsoft Silverlight 4 Business Application Development, we shall understand Expression Blend and how to use it in conjunction with Visual Studio.

Creating applications in Expression Blend

What we've done so far falls short of some of the things you may have already seen and done in Silverlight. Hand editing XAML, assisted by Intellisense, works just fine to a point, but to create anything complex requires another tool to assist with turning our vision into code.

Intellisense is a feature of Visual Studio and Blend that auto-completes text when you start typing a keyword, method, or variable name.

Expression Blend may scare off developers at first with its radically different interface, but if you look more closely, you'll see that Blend has a lot in common with Visual Studio. For starters, both tools use the same Solution and Project file format. That means it's 100% compatible and enables tighter integration between developers and designers. You could even have the same project open in both Visual Studio and in Blend at the same time. Just be prepared to see the File Modified dialog box like the one below when switching between the two applications:

Microsoft Silverlight 4 Business Application Development: Beginner’s Guide

If you've worked with designers on a project before, they typically mock up an interface in a graphics program and ship it off to the development team. Many times, a simple graphic embellishment can cause us developers to develop heartburn. Anyone who's ever had to implement a rounded corner in HTML knows the special kind of frustration that it brings along. Here's the good news: those days are over with Silverlight.

A crash course in Expression Blend

In the following screenshot, our CakeNavigationButton project is loaded into Expression Blend. Blend can be a bit daunting at first for developers that are used to Visual Studio as Blend's interface is dense with a lot of subtle cues. Solutions and projects are opened in Blend in the same manner as you would in Visual Studio.

Just like in Visual Studio, you can customize Expression Blend's interface to suit your preference. You can move tabs around, dock, and undock them to create a workspace that works best for you as the following screenshot demonstrates:

Microsoft Silverlight 4 Business Application Development: Beginner’s Guide

If you look at the CakeNavigationButton project, on the left hand side of the application window, you have the toolbar, which is substantially different from the toolbox in Visual Studio.

The toolbar in Blend more closely resembles the toolbar in graphics editing software such as Adobe Photoshop or Adobe Illustrator. If you move the mouse over each button, you will see a tooltip that tells you what that button does, as well as the button's keyboard shortcut. In the upper-left corner, you'll notice a tab labeled Projects. This is functionally equivalent to the Solution Explorer in Visual Studio. The asterisk next to MainPage.XAML indicates that the file has not been saved. Examine the next screenshot to see Blend's equivalent to Visual Studio's Solution Explorer:

Microsoft Silverlight 4 Business Application Development: Beginner’s Guide

If we look at the following screenshot, we find the Document tab control and the design surface, which Blend calls the art board. On the upper-right of the art board, there are three small buttons to control the switch between Design view, XAML view, or Split view.

On the lower edge of the art board, there are controls to modify the view of the design surface. You can zoom in to take a closer look, turn on snap grid visibility, and turn on or off the snapping to snap lines.

 

Microsoft Silverlight 4 Business Application Development: Beginner’s Guide

If we then move to the upper-right corner of the next screen, we will see the Properties tab, which is a much more evolved version of the Properties tab in Visual Studio. As you can see in this screenshot, the color picker has a lot more to offer. There's also a search feature that narrows down the items in the tab based on the property name you type in.

 

Microsoft Silverlight 4 Business Application Development: Beginner’s Guide

At the lower left side of the next screen, there is the Objects and Timeline view, which shows the object hierarchy of the open document. Since we have the MainPage.XAML of our CakeNavigationButtons project, the view has StackPanel with six Buttons all inside a grid named LayoutRoot inside of a UserControl. Clicking on an item in this view selects the item on the art board and vice versa.

Microsoft Silverlight 4 Business Application Development: Beginner’s Guide

Expression Blend is an intricate and rich application.

Time for action – styles revisited

Earlier in this chapter, we created and referenced a style directly in the XAML in Visual Studio. Let's modify the style we made in Blend to see how to do it graphically. To do this, we will need to:

  1. Open up the CakeNavigationButtons solution in Expression Blend.
  2. In the upper right corner, there are three tabs (Properties, Resources, and Data).
  3. On the Resources tab, expand the tree node marked [UserControl] and click on the button highlighted below to edit the [Button default] resource.
  4. Microsoft Silverlight 4 Business Application Development: Beginner’s Guide

  5. Your art board should look something like this:
  6. Microsoft Silverlight 4 Business Application Development: Beginner’s Guide

Microsoft Silverlight 4 Business Application Development: Beginner’s Guide Build enterprise-ready business applications with Microsoft Silverlight 4 with this book and eBook
Published: April 2010
eBook Price: £20.99
Book Price: £33.99
See more
Select your format and quantity:
  1. Click on the Properties tab and scroll down to the Text section:
  2. Microsoft Silverlight 4 Business Application Development: Beginner’s Guide

  3. Change the FontSize to 14 and click on the B and the I buttons to toggle on Bold and Italic.
  4. Type cursor into the Search box. Notice how the Properties tab displays only the Cursor property.
  5. Next, change the value in the drop down list to Hand:
  6. Microsoft Silverlight 4 Business Application Development: Beginner’s Guide

  7. Type margin into the search box and put 5 into each of the text boxes as shown in the following screenshot:
  8. Microsoft Silverlight 4 Business Application Development: Beginner’s Guide

  9. Look over to the left hand side of the screen; you'll see a tab named Objects and Timeline. Click on the button with the up arrow that I've highlighted in the following screenshot. This will get you out of Style editing mode and back into the main level of our application:
  10. Microsoft Silverlight 4 Business Application Development: Beginner’s Guide

  11. Choose Run Project from the Project menu or hit F5 to run the project.
  12. Notice what's changed. There is now a space around each button, the font's appearance has changed and the cursor changes to a hand when you mouse over each of the buttons. Your application will now look similar to the following screenshot:
  13. Microsoft Silverlight 4 Business Application Development: Beginner’s Guide

  14. The buttons have a red tint to them, but there is still some way to go.

What just happened?

We have just edited a style in Expression Blend and the software did all the heavy lifting for us. If you take a peek at the XAML markup, you will see that the Style has been expanded to include a few more Setter nodes. Each one corresponds to the changes that we made:

<Style TargetType="Button">
<Setter Property="FontSize" Value="14"/>
<Setter Property="Background" Value="Red"/>
<Setter Property="Cursor" Value="Hand"/>
<Setter Property="FontStyle" Value="Italic"/>
<Setter Property="FontWeight" Value="Bold"/>
<Setter Property="Margin" Value="5,5,5,5"/>
</Style>

You most certainly could have created this XAML by hand, but as you've just seen, it's often faster to use Blend for this. In many real world scenarios, you will have to get your hands dirty in the XAML from time to time to tweak a value.

Have a go hero

So, we have a style that defines the way we would like our buttons to look. What if we wanted to override certain properties? For example, if you wanted the font size on the Home button to be different than the others, you could specify a smaller or larger value. Once again, you can do this in Blend via the Properties tab or in the XAML using the following code:

<Button Content="Home" FontSize="9" />

By using this code, you will be presented with this screenshot:

Microsoft Silverlight 4 Business Application Development: Beginner’s Guide

Alternatively, you could define another style; one that specifies a smaller font size. We've seen that done in XAML, but not in Blend yet.

Let's do that now. Make sure that the UserControl element is selected, then click on the Object menu, and then Edit Style|Create Empty... You will then see the following dialog box:

Microsoft Silverlight 4 Business Application Development: Beginner’s Guide

Next, change the Name to smallerTextStyle then click OK. Use the Properties tab to change the font size to 9. Feel free to change some other properties too.

When you are finished, click the up button on the Objects and Timeline tab to exit style editing mode. Once you are back in the main view, select the Home button. Type style into the search box on the Properties tab (you will find it on the right-hand side of Blend's window). Under Miscellaneous, you will see a Style property with a little square next to it as in the screenshot below. In Blend, this means that there are more properties for you to edit. Click the square to bring up the Advanced Property Options context menu.

Microsoft Silverlight 4 Business Application Development: Beginner’s Guide

Once you click on the square, the following context menu appears. Choose Local Resource|smallerTextStyle from the sub-menu just as you see it in the following screenshot:

Microsoft Silverlight 4 Business Application Development: Beginner’s Guide

Run the solution again or look at the art board to see how the button has changed. You can experiment with assigning this style to some of the other buttons, editing the existing styles, or creating new styles. On buttons where the smallerTextStyle is applied, the button text will be smaller. On buttons where the default style is applied, the button text will be larger.

Summary

In this article, we learnt about Expression Blend.


If you have read this article you may be interested to view :

Microsoft Silverlight 4 Business Application Development: Beginner’s Guide Build enterprise-ready business applications with Microsoft Silverlight 4 with this book and eBook
Published: April 2010
eBook Price: £20.99
Book Price: £33.99
See more
Select your format and quantity:

About the Author :


Frank LaVigne

Frank LaVigne has been hooked on software development since he was 12, when he got his own Commodore 64 computer. Since then, he's worked as developer for fi nancial fi rms on Wall Street and also in Europe. He has worked on various Tablet PC soluti ons and on building advanced user experiences in Silverlight and WPF. He lives in the suburbs of Washington, DC. He founded the CapArea.NET User Group Silverlight Special Interest Group and has been recognized by Microsoft as a Tablet PC MVP. He blogs regularly at www.FranksWorld.com.

 

Books From Packt


Microsoft Silverlight 4 Data and Services Cookbook
Microsoft Silverlight 4 Data and Services Cookbook

.NET Compact Framework 3.5 Data Driven Applications
.NET Compact Framework 3.5 Data Driven Applications

Blender 3D 2.49 Incredible Machines
Blender 3D 2.49 Incredible Machines

SketchUp 7.1 for Architectural Visualization: Beginner's Guide
SketchUp 7.1 for Architectural Visualization: Beginner's Guide

Firebug 1.5: Editing, Debugging, and Monitoring Web Pages
Firebug 1.5: Editing, Debugging, and Monitoring Web Pages

Grok 1.0 Web Development
Grok 1.0 Web Development

3D Game Development with Microsoft Silverlight 3: Beginner's Guide
3D Game Development with Microsoft Silverlight 3: Beginner's Guide

Moodle 1.9 Theme Design: Beginner's Guide
Moodle 1.9 Theme Design: Beginner's Guide


Code Download and Errata
Packt Anytime, Anywhere
Register Books
Print Upgrades
eBook Downloads
Video Support
Contact Us
Awards Voting Nominations Previous Winners
Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
Resources
Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software