Expression Blend and Design

The team blog of the Expression Blend and Design products.

Fabrikam Catalog Part 3: Special Effects

Fabrikam Catalog Part 3: Special Effects

Rate This
  • Comments 19

Download the sample project files for the RC build of Expression Blend

Fabrikam catalog part 3: Special effects

Adding visual effects and animation to an interactive product catalog by using Microsoft® Expression Blend™

Contents

Overview

The finished project

The finished project

This tutorial shows you how to add visual effects and animation to a Expression Blend project. This tutorial starts from a pre-built project that you can download from FabrikamCatalogControlTemplates.zip. If you have completed the tutorial Fabrikam catalog part 2: Control Templates, you can use the project that you created in that tutorial.

At the completion of this tutorial, your finished project will display—in two adjacent panes—a catalog of the products that are manufactured by the fictitious company Fabrikam. The project also showcases three stylized and appealing visual effects. First, the combination of the gradient background and the reflection effect gives the illusion that the master pane and the details pane are standing on a highly-polished dark surface. Second, a spotlight orbits the document and also appears to be reflected in the polished surface. Third, the transition between products is cued by a fly-in animation in which the details pane rotates and scales up into the document from behind the master pane.

If you want to work through this tutorial while looking at an example of the completed project, you can open a second instance of Expression Blend and view the FabrikamCatalogSpecialEffects sample project which you can download from FabrikamCatalogSpecialEffects.zip.

Features that you will learn about in this tutorial

  • Make Visual Brush Resource tool
  • Transformation tools
  • Animation workspace
  • Animation timeline
  • Convert to Motion Path tool
  • Animation triggers

Task 1: Opening and saving the sample project

  1. Download the sample project from FabrikamCatalogSpecialEffects.zip. If you completed the tutorial Fabrikam catalog part 2: Control templates, you can use the project that you created in that tutorial.
  2. Open the project in Expression Blend. 
    Tip If you previously had a project open, you might first see a dialog box asking whether you want to save or discard your current project before opening the sample project.
  3. Press F5 to make sure that your project builds and runs before you continue with the steps in this tutorial.
    Tip As you work in Expression Blend, your changes take place in memory and not on your hard disk, so be sure to save often.

Task 2: Adding a reflection effect

The following procedure shows you how to use the Make Visual Brush Resource tool to create an element in your application that shoes a mirror image of part of your application.

  1. Under Objects and Timeline in the Interaction panel, double-click LayoutRoot to activate it (if it is not already activated).
    Notice that when you activate the element, a yellow bounding box appears around its name.
    Tip In Expression Blend, you can select or activate elements. You can select an element without activating it.
    Double-clicking an element is called activating the element. The activated element is identified by a yellow bounding box around the element name. To add child elements to an element (which will become the parent element), double-click the parent element under Objects and Timeline, and then add the child element.
    Clicking an element once is called selection. The selected element is identified by a highlighted background color. To change the properties of an element, click the element name once under Objects and Timeline.
  2. In the Toolbox, select Rectangle Rectangle tool.
  3. On the artboard, draw a Rectangle directly beneath and the same size as MainGrid. Doing so will require you to draw off the bottom of the document. Your rectangle should look something like the following screenshot.

    New rectangle drawn on the artboard

    Tip To be able to see enough of the artboard to draw your rectangle, you might have to zoom out the artboard view. To zoom out, enter a zoom value in the text box at the bottom of the artboard Zoom textbox, click the arrow next to the zoom value, or rotate your mouse wheel while holding down CTRL.
    Tip To undo changes in Expression Blend, press CTRL+Z. Alternately, you can click Undo on the Edit menu. The Undo menu item will include a brief statement about the specific step that it will undo. You can undo an unlimited number of steps in Expression Blend, but your undo history is cleared each time that you build your application.
  4. Under Objects and Timeline, select the [Rectangle] element and rename it to Reflection.
  5. Under Objects and Timeline, select the MainGrid element. On the Tools menu, point to Make Brush Resource, and then click Make Visual Brush Resource.
    The Create VisualBrush Resource dialog box appears. In the next few steps, you will create a brush that can make any other element look like MainGrid.
  6. In the Resource name (Key) field of the Create VisualBrush Resource dialog box, enter ReflectionBrush.
    This sets a name for your visual brush in the resource dictionary for your project so that you can set this brush as the brush for any element. You can view your visual brush in the Resources panel under Window.
  7. In the Define in field, select the This document radio button and make sure that Window: Window is selected in the list.
    The Define in field indicates the resource dictionary in which to define your new visual brush. Selecting Window: Window means that this visual brush will be visible to all elements in the window.
  8. Click OK.
    You have now created a VisualBrush named ReflectionBrush that can make any element in your project look like MainGrid. You can now apply this brush to your Reflection element. The ReflectionBrush brush has been placed into the resource dictionary, which you can view in the Window node of the Resources panel. (The Resources panel occurs together with the Project panel and the Properties panel on the right side of the artboard.)
  9. With the Reflection element selected under Objects and Timeline, locate and select the Fill property under Brushes in the Properties panel.
    Tip If you have trouble locating a particular property, expand the categories in the Properties panel and use the scroll bar on the right side of the panel to scroll up or down to locate the property, or type part of the property name into the Search box near the top of the panel. When you use Search, remember to clear the Search box when you are done; the properties in the Properties panel will remain filtered by whatever is typed into the Search box, until you clear it. To clear the Search box, click the Clear Clear search box button button.
    Tip If a category in the Properties panel is collapsed, expand it by clicking the Expand Category icon on the title bar of the category, or by simply click the title bar of the category.
  10. With the Fill property selected under Brushes in the Properties panel, click the Brush Resources Brush resources button button. Select ReflectionBrush from the list of brush resources.
    The image of the MainGrid element is projected onto the Reflection Rectangle.
    Recall that the Fill property is always set to a Brush of some kind. In previous Fabrikam tutorials, you have set the Fill of a Rectangle to a Solid Color Brush or Linear Gradient Brush. ReflectionBrush is a different type of brush—a VisualBrush—that dynamically mimics the appearance of a Visual. Think of it as pointing a Web camera at MainGrid and showing the live feed in Reflection. In Windows Presentation Foundation (WPF), any visible element is a Visual, and in this case the Visual is MainGrid.
  11. With the Reflection element selected under Objects and Timeline, look under Transform in the Properties panel. Click the arrow at the bottom to display the advanced LayoutTransform properties. Select the Flip tab Flip transform tab and then click the Flip Y button.
    This creates a mirror effect below MainGrid. Notice that the corner radius adorners Corner radius cursor of the Reflection element are now in the lower-left corner. (Adorners are visible when the Selection tool is selected.)
    Tip LayoutTransform properties are applied to the object when layout actions are performed when the object first appears in the application.
    RenderTransform properties are applied to the object during rendering, which can occur at any time, and multiple times, after layout. A render transform does not regenerate layout size or render size information. Render transforms are typically used for animation.
  12. With the Reflection element selected under Objects and Timeline, set the Stroke property under Brushes in the Properties panel to No Brush.
  13. With the Reflection element still selected, set the OpacityMask property under Brushes in the Properties panel to Gradient Brush. Select Brush Transform Brush Transform tool from the Toolbox and drag the arrow on the artboard while holding the SHIFT key to rotate the brush so that the arrow points down. Change both gradient stops to White and  move the right-hand stop to the middle of the gradient bar. Set the Alpha property of the left-hand stop to 50 and set the alpha of the center stop to 0. This will cause the element to be painted semi-transparently at the beginning of the gradient and fully transparently from the center to the end.
  14. On the Project menu click Test Project (F5). When the application starts, test that your reflection effect resembles the one illustrated in the tutorial’s overview and that it tracks changes to the product selection.
    You might notice that when you resize the application window, your reflection does not resize properly. To fix the resizing problem, you can divide the LayoutRoot grid into three rows and change the Layout properties.
  15. Under Objects and Timeline, activate the LayoutRoot element.
  16. In the Toolbox, click Selection Selection tool. On the artboard, move the mouse pointer over the thick blue ruler area at the left side of LayoutRoot. An orange row ruler will follow your mouse pointer and indicate where a new row divider would be placed should you click.
    Click to create a new row divider at the top of MainGrid so that MainGrid will be in the second row.
    Click to create another new row divider between MainGrid and Reflection, at the bottom of MainGrid.
    Blue row dividers appear inside LayoutRoot.
  17. With MainGrid selected under Objects and Timeline, set the following properties under Layout in the Properties panel:
    • Set Width and Height to Auto if they are not already set to Auto.
    • Set the Row and RowSpan properties to 1 if they are not already set to 1.
    • Set the HorizontalAlignment and VerticalAlignment properties to Stretch if they are not already set to Stretch.
    • Set the Top and Bottom Margin properties to 0 if they are not already set to 0.
  18. With Reflection selected under Objects and Timeline, set the same property values as above with two exception - set the Row property to 2 and set the Top Margin property to 8.
    Reflection will now resize with the application window and keep its proportions. However, the reflection of MainGrid will be squished because the height of Reflection is smaller than MainGrid.
  19. With Reflection selected under Objects and Timeline, click the name of the Height property under Layout in the Properties panel, and select Data Binding.
    The Create Data Binding dialog appears.
    Apart from binding to a data source like an XML file or a database, you can also bind to values of properties of elements in your project.
  20. In the Create Data Binding dialog, select the Element Property tab.
  21. In the Scene Elements field, expand LayoutRoot and select MainGrid.
  22. In the Properties field, select ActualHeight, and then click Finish.
    The height of the Reflection rectangle will now stay the same as the height of MainGrid.
  23. On the Project menu click Test Project (F5) to test your application again.

Task 3: Adding a faux spotlight effect

The following procedure shows you how to create the effect of a spotlight which appears reflected in a polished surface. The spotlight uses animation to orbit the catalog.

  1. Under Objects and Timeline in the Interaction panel, double-click LayoutRoot to activate it.
  2. In the Toolbox, select Ellipse Ellipse tool.
  3. On the artboard, draw a narrow Ellipse, at the base of MainGrid and nearly as wide as the scene. This ellipse will play the part of your spotlight.
  4. Under Objects and Timeline, select [Ellipse] and rename it Spotlight.
  5. With Spotlight selected under Objects and Timeline, look under Brushes in the Properties panel. Set the Stroke and OpacityMask properties to No Brush No Brush . To adjust Spotlight’s opacity, set the Fill property to Gradient Brush Gradient brush . The Gradient Brush is Linear by default. Change to Radial by selecting the Radial Gradient icon Radial gradient button at the bottom left under Brushes. Make both of the gradient stops white, and set the Alpha of the left-hand stop to 100 and the right-hand stop to 0.
  6. The next Ellipse you will draw represents the path you wish your orbiting spotlight to follow. It will be large, so zoom out the artboard until the artboard is at about 50%.
  7. With LayoutRoot activated under Objects and Timeline, draw another Ellipse, again at the base of MainGrid, but this time a little wider than the artboard. You can adjust the size and location of SpotlightPath by using the blue adorners on the artboard.
  8. Under Objects and Timeline, select [Ellipse] and rename it SpotlightPath.
  9. Select SpotlightPath under Objects and Timeline. From the Object menu, click Path, and then click Convert to Motion Path. The Choose Target for Motion Path dialog box is displayed. Select Spotlight and click OK.
  10. There is no more need for SpotlightPath so you can delete it under Objects and Timeline (select it and then press DELETE).
    Tip The Convert to Motion Path command does the following things:
    • It copies the shape of SpotlightPath, which is why you can subsequently delete it.
    • It creates a new timeline (Timeline1) in which Spotlight moves along a path defined by the shape of SpotlightPath. In Expression Blend, a timeline is richer than the static snapshots used to plan movies and animations. Here, the timeline is the definition of the animation itself.
    • It sets up a trigger to cue the animation timeline, and the event on the trigger is the Window.Loaded event. You can view the specifics of the trigger by selecting Window.Loaded under Triggers in the Interaction panel which displays the specifics in the bottom of Triggers .
    • It moves Spotlight to take up position at the beginning of its storyboard’s path.
  11. Under Objects and Timeline, Timeline1 is selected. Click Play to preview the storyboard.
    The default length of the animation is 2 seconds.
  12. Press F7 to switch to the Animation Workspace.
    This moves the Interaction panel below the artboard.
  13. With Timeline1 selected at the top of Objects and Timeline in the Interaction panel, expand the element tree beneath Spotlight right down to MotionPath. Drag the blue bar at the right end of MotionPath‘s timeline out to the 10 second mark. Click Play again to view the change to the length of the animation.

    Endpoint of motion path

    Close-up of the end point of the motion path on the timeline (at 10 second mark)

  14. With Timeline1 still selected, right-click MotionPath and click Edit Repeat Count. The Edit Repeat dialog box is displayed. Set Repeat to Forever and click OK.
    Now the spotlight animation will loop forever when you run your application (not when you click Play in Expression Blend).
  15. So that the spotlight disappears behind the panes at the appropriate part of its orbit, right-click Spotlight under Objects and Timeline, click Order, and then click Send to Back.
  16. Test the project (F5) to see your changes.
    If you want to change the path of your spotlight, you can create a new Ellipse and use the Convert to Motion Path tool again. The previous animation will be deleted and replaced with the new one generated by Convert to Motion Path.

Task 4: Adding an animation effect

The following procedure shows you how to use animation to make the DetailsPane fly into view from behind MasterPane. This animation timeline will be triggered when the application loads and when an item is selected in MasterList.

  1. Under Objects and Timeline in the Interaction panel, click Create New Timeline New timeline button. The Name Timeline dialog box is displayed. In Name type FlyIn and click OK.
    The new FlyIn timeline is selected in the dropdown box under Objects and Timeline.
  2. So that the DetailsPane begins its fly-in from behind the MasterPane, right-click DetailsPane under Objects and Timeline, click Order, and then click Send Backward.
    The DetailsPane node moves below the MasterPane node, indicating that it is lower in Z-order (the order that determines which elements appear in front of other elements).
  3. To begin recording your animation sequence, select DetailsPane under Objects and Timeline, move the timeline playhead Timeline playhead to second 0, and then click Record Keyframe Record Keyframe button.
    A keyframe icon appears on the timeline at second 0.
  4. Drag the key frame you just recorded to second 0.5 on the timeline.
    This is the end position of DetailsPane in your animation sequence.
  5. With the timeline play head still at second 0, hold down SHIFT and ALT while dragging a corner of DetailsPane to make it smaller.
    With this first change, a new keyframe was created at second 0. Changes are automatically recorded in keyframes set at the location of the play head. Expand DetailsPane and RenderTransform to see the Translation element where the new keyframe was set.
    Tip When resizing an element on the artboard, SHIFT constrains proportions and ALT maintains the original center point. Release the mouse button before releasing the SHIFT and ALT keys.
    Tip In Expression Blend, animation is accomplished by recording changes in properties.
  6. Hold down SHIFT and drag DetailsPane behind the center of MasterGrid.
    You might notice that your reflection displays a stretched view of MasterPane. You will fix this in a later step.
    Tip When moving an element on the artboard, SHIFT constrains the movement to horizontal or vertical depending on the initial direction. Release the mouse button before releasing SHIFT.
  7. Under Transform in the Properties panel, select the Rotation Rotation transform tab tab under RenderTransform, and set the Angle value to -90 to rotate the pane counterclockwise 90 degrees.
  8. Click Play to preview the timeline.
    You should see the details pane growing in size as it flies into view from behind the master pane.
    The final job in building this animation is to cause the FlyIn timeline to be triggered by a change to MasterList’s selected item. The animation is already triggered when the application loads because that trigger gets created for the Window.Loaded event when you create the timeline. Triggering the animation in any other situation needs to be configured by you.
  9. With the FlyIn timeline still selected under Objects and Timeline, activate MasterList.
  10. Under Triggers in the Interaction panel, click + Event.
    An new Window.Loaded event trigger is added to the list.
  11. Under Triggers in the Interaction panel, select the new event trigger. In the bottom half of Triggers in the Interaction panel, you can edit the trigger specification by clicking the arrows next to the dropdown boxes. Change the trigger so that it states When MasterList.SelectionChanged is raised.
  12. Click the plus sign next to the trigger specification to add a new action. Change the new action to FlyIn.Begin.
    Now, the FlyIn animation will be triggered when an item is selected in the MasterList.
  13. To fix the reflection problem, select MainGrid under Objects and Timeline, and then under Brushes in the Properties panel, change the Background property from No Brush to Solid Brush with an Alpha of 0.
    Tip When No Brush is used as the Background for an element, Windows Presentation Foundation (WPF) measures the element based on how much of the element's contents is visible during its animation phase. For example, whatever the measured size of MainGrid (with or without DetailsPane showing), WPF will stretch what it finds to fit into the Reflection rectangle. As long as an element's Background property is something other than No Brush , the element will always take up the same real estate as its bounding box. 
  14. One final tweak is to take into account the possibility that a corner of the DetailsPane might extend beyond the bottom of MainGrid while it is rotating. To prevent this from causing the layout of your elements to shift during the animation, select MainGrid under Objects and Timeline, and in the advanced section under Appearance in the Properties panel, set the ClipToBounds property to True (check the box).
    This prevents any part of MainGrid to appear outside of its bounding box.
  15. Now you’re ready to go ahead and test (F5) the finished application and experience all of your functionality and sparkly visuals in full effect.
Leave a Comment
  • Please add 4 and 6 and type the answer here:
  • Post
  • To view a sample or tutorial, click on one of thumbnails or links below. Some samples also have supporting...
  • PingBack from http://blogs.msdn.com/expression/pages/fabrikam-catalog-part-3-special-effects.aspx

  • More screen shots would be helpful so that the reader would have a visual reference of how things are changing after a significant set of steps.  Also, the text can be somewhat tiresome to read.  Condensing the descriptions, and allowing them to wrap to the browser window, might help with the readability.

  • nice stuff and interesting to go through.

    about the format, it would be clearer if the tutorial steps were split up into basic actions, i.e. in fontcolor black, and backgroundinfo/explanation would be in a lighter colour. that way it would be easier to just follow the instructions and look into further info only when necessary.

  • If you go through all three in order you actually run through this tutorial very quickly, and it gives a large amount of satisfaction :D

  • Very nice tutorial. The reflection is very attractive and when coupled with animation it looks stunning.  I would like to see another series of tutorials that deal with advanced effects, such as combining visual brushes, data binding and animations that spill outside the layout control. Use of the page element, clipping and xaml arrays would be a nice progression in this area.

    Once again, great work!

  • it helps me a lot, i learned lot of things regarding WPF thanks !

  • Thank you for this tutorial. Almost everything worked very well. The only problem I had was that the reflection was affected by the motion path and would move around with the spotlight! I couldn't figure out how to 'disconnect' them.

  • Steps 3-5 in Task 4 are a bit confusing with the wording second .0. I was actually looking for a second 0 as in two zeros in the timeline. But you might explain the timeline a bit more. There is a step you skip on going from 0 to .5 and back to 0. You say "With the timeline play head still at second 0" But prior to that we moved it to .5.

    But the second time thru I have got to the point where I see the next step and can do it on my own without looking at the instructions. The text was tiresome to read but it was necessary in case you missed a step. Perhaps a few more screen shots of the properties panel would help to verfiy settings. I erally hope to find more tutorials like this.

    Thanks.

  • To developeer_46038:

    When there is a step to move the dot from point 0 to point 0.5 what we actually do is recording the objects positions and sizes as they should be presented to reader. When we record those positions on point 0 we just move those recordings to point 0.5 while the timeline play head is still at second 0. That means that doing any other changes will affect the objects at the beginning of the timeline.

    When recording in on, changes we made to objects are always affected at the point that indicates timeline play head.

  • Step 13: I can't get the arrow to appear at all so I can't get it point down.

    I am using Expression Blend 2 - is it any different?

  • I cannot make step 13 work.  The the "Brush Transform" button in the toolbox (on my left) is disabled.   When it is enabled dragging it does nothing....

    ???

  • So I figured out how to transform the brush in step 13.  As Jonathan stated,  I am using Expression Blend V2.   When you click on the brush transform arrow, it draws an arrow over the selected object that the brush applies to....you then drag the ends of the brush around to change your gradient pattern

  • I give up.  I get lost at Task 2  16-19.  Maybe again its because I'm using the latest version of Blend and the tut is not up to date.  Everything looks and works fine until step 16 and then the main grid gets compressed completely and the reflection disappears around step 19.

    I really wish msdn would put together some video tutorials.  So far the best place to learn Blend 2 is Lynda and You Tube.  I'm part of a software company that is working to design the graphical UI for a new release.  They are really wanting to use WPF and Blend for all of it and so I'm trying to get brought up to speed as quickly as possible.

    If anyone knows any up-to-date tuts for Blend 2, click on my name and email me with the contact info on my website.

  • Overall, it is awesome work!

    Some suggestion though, wording are some what a bit of confusion somewhere.  And yes, would be nice if there are more screen references.

    Anyway, I could follow everything without problem.

    Looking forward to seeing a new more advanced tutorial.

    Once again, a great work!

Page 1 of 2 (19 items) 12