Feed on
Posts
Comments

If you have a computer with the Silverlight 2 developer bits installed you might see the following message when installing Silverlight 3.

Unable to install Silverlight. Your Silverlight developer components are out of date.

Here’s a typical install sequence on a Windows Vista computer that results in this error message.

 

1. Navigate to a Web site with Sliverlight 3 content or go to the Microsoft Silverlight site.  
2. Choose to install Silverlight.  In this example I’m on the Microsoft site and clicking the Windows Runtime button. image
3. In the File Download dialog choose Run. image
4. In the Internet Explorer Security dialog choose Run. image
5. In the Silverlight Installer dialog choose the Install Now button. image
6. Congratulations.  You are a developer and need to do some extra work to install Silverlight. image

Uninstalling Silverlight 2 Developer Tools

Before removing Silverlight 2 from your computer you might want to read the Silverlight 3 release notes.  It contains some useful information about updating Silverlight 2 applications to version 3 and other helpful topic. For example: did you know that once you’ve removed the Silverlight 2 SDK you won’t be able to work with Silverlight 2 projects in Visual Studio 2008?  In other words Visual Studio cannot work with more that a single Silverlight SDK at one time. 

Open the Programs and Features control panel and remove the Silverlight 2 SDK and Silverlight Tools for Visual Studio 2008 SP1 applications (Figure 1).

image

Figure 1:  Removing the Silverlight 2 applications.

Now that you have a clean machine it’s time to install the Silverlight 3 SDK. 

Installing the Silverlight 3 Developer Tools

SeeTheLight.com is the virtual launch site for Silverlight 3.  If you snoop around on the site for a few minutes you’ll find a link to their Silverlight developer resources.

Here’s the two of the installers that you should run to get ready to write Silverlight 3 applications.

Oh to be the first kid in the neighborhood to get that new video game that the rest of your friends covet. What a sweet feeling to learn the secrets of the game, master the arcane moves and beat the game before everyone else. Once you’ve established yourself as the resident expert you’ll soon find your friends peppering you with a steady stream of questions on how to beat that grisly boss monster or solve that crafty last puzzle.

clip_image001[4]

To stretch the analogy a little; in Redmond that kid is Microsoft Surface and the game they been playing for the last couple years is called multi-touch. They were one of the first groups to work on multi-touch inside Microsoft and they built a set of APIs that brought the awesomeness of multi-touch to the big table. Now the rest of the Microsoft kids are clamoring for their knowledge.

Windows 7, the next version of Microsoft’s ubiquitous operating system, has full support for multi-touch and exposes a number of touch APIs for the Windows developer. A few of these libraries come direct from the Surface team. In this article I will cover one of these Surface libraries; the Manipulation processor.

Nuts and Bolts

There are a number of terms to discuss before the digging into the sample code.

Fingers: Users can touch the screen with one or more fingers. They can also brush the screen with the palm of their hand or with an item like a paintbrush. The touchscreen hardware will turn some of these ‘touches’ into input that is processed by Windows. Windows sends out messages, either WM_TOUCH or WM_GESTURE, to interested applications.

Gesture: A gesture is a sequence of touch moves that mean something special to the OS. Gestures are built in to the Windows 7 OS so will be consistent across all applications.

The Gesture Catalog

Scroll : The most popular gesture during testing and usability studies. Drag up or down on the content. If the window has a scrollbar the touch API will interpret this motion as if you were interacting with the scrollbar.

Drag: Touch and slide your finger on screen. This is similar to dragging content with your mouse.

clip_image003[4]

Tap: When the user touches the screen and lifts their finger before the preset ‘hold time’ the OS consider that to be a Tap.

Double-Tap: Same as the Tap gesture except that the user touches the screen twice in rapid succession.

Two Finger Tap: Similar to the Tap gesture except you tap with two fingers simultaneously.

Zoom : Pinch two fingers together to zoom in on an element. Spread them apart to zoom out on an element.

clip_image005[5]

Rotate: Touch two locations on an item and twist. This is interpreted as a rotation.

clip_image007[4]

Press and Hold: Hold a finger to the screen for longer than the ‘hold time’ and get a Hold. This is the same a mouse right-click.

Flick: A fast dragging motion to the left or right is interpreted as a Flick. Useful in applications, like a browser, that contain forward and backward features.

Most of these gestures work in applications running on Windows 7 without any extra coding by the developer. The Rotate and Two Finger Tap gestures are the exceptions to this rule.

Manipulation and Inertia

Gestures are powerful and easy to use. In fact gestures just work in most Windows applications. But you can’t easily combine gestures. If the user makes a Zoom gesture you can catch the event and scale an element, but you can’t move the element at the same time. If you want to move an item you have to listen for the Drag gesture instead. The touch framework offers two classes specialize in interpreting complex touch gestures and converting them to easy to use matrix transforms.

Manipulation processor: This is the primary engine that gathers sophisticated touch movements and converts them into a matrix transform for your consumption.

Inertia processor: If the Manipulation processer detects that movement had crossed a velocity threshold it can invoke the Inertia processer. This processor exposes methods that provide simple physics calculations to simulate friction drag, inertial damping, smooth deceleration, edge detection and boundary bounce.

WPF and Touch

The Surface team wrote the Manipulation and Inertia processors a number of years ago. Their choice at the time was to build them as COM components. The Window 7 team on the other hand wrote most of their touch APIs in native code. The WPF team is creating managed wrappers around both these libraries to simplify your life. They are exposing most of the touch API through changes to UIElement. For example they have added some new events that return Manipulation and Inertia references.

· ManipulationStarted

· ManipulationDelta

· ManipulationInertiaStarting

· ManipulationCompleted

· ManipulationBoundaryFeedback

What’s next

In part two of this article I will show you how to use the Manipulation events to listen to the touch framework and modify your UI elements.

A common UI metaphor in recent times is the circular wait cursor or progress indicator. This article shows some easy techniques within Expression Blend 2 that simplify creating this modern UI indicator. After showing how to easily layout multiple child elements in a 360-degree pattern, I will show animation techniques for spinning, sizing and fading sub-elements.

Part Two

In the first installment of this article I showed some techniques for implementing circular animations. The trek continues in this installment where I will show you how to arrange elements evenly about the perimeter of a circle and how to recreate the Silverlight loading animation.

[Arranging Shapes in a Circle with Expression Blend, Part One]

Evenly Placing Elements Around a Center Point

The Expression Blend designer makes it easy to arrange items around the perimeter of a circle. Arranging shapes in this fashion is a common UI pattern. Take this simulated clock face (Figure 1) for example. It has 12 rectangles arranged evenly about the outer rim.  Not only are they equal distance apart but each rectangle is also angled at 30 degrees from its neighbors.

image

Figure 1: Simple clock face.

The kaleidoscopic patterns that emerge from these simple curved arrangements are boundless.  I could change the rectangles to triangles and hide the underlying circle and suddenly have a pattern that suggests the outline of a stylized sun. For the next demonstration I will create a pattern of green triangles (Figure 2) pointing outward like points of a compass.

image

Figure 2: Eight triangle pattern.

The repetitive pattern (Figure 2) is generated from a humble green triangle (Figure 3) below, which is created with the Path class (watch Video 1).

image

Figure 3: Green triangular path.

Video 1: Creating triangle path.

 

The Blend Artboard provides five control points for manipulating an element’s rotation transform with your mouse.  The four corner points (corner white dots in Figure 4) are interactive handles that you can use to spin the object thereby changing the rotation angle property. Normally the center point is exactly that – centered within the shape bounding rectangle.  But it doesn’t have to stay there.

The white dot in the center of the green triangle (Figure 4) is the fifth control point and it controls where the center of the rotation will occur. If you drag this center point to a new location it changes the CenterPoint property and it will affect future rotations.

image 

Figure 4: The rotation controls points.

To make my pattern I want to rotate each triangle 45 degrees from its neighbors. The pattern won’t look right if you use the default center point however.  Instead I want each of the triangles in the pattern to share a common center point (the center of the larger circle).

image

Figure 5: Common center point.

It’s painless to do this in Blend as long as you know the steps to follow. I’ve recorded a short video (Video 2) that walks you through the actions necessary to make this pattern.

Video 2: Even spacing of elements.

 

That’s it.  Now that you have the pattern finished it is simple to make a 360-degree animation from the composite parts (Video 3).

Video 3: Even spacing finished.

Silverlight Animation

It’s time to put some pizzazz in our animations.  To mimic the Silverlight animation I need to build my UI from blue circles instead of green triangles. Each blue circle needs to animate independently from the others as it whirls about the edge of the circle.  I could choose to use a variety of effects.  I could spin the shape, have it fade slowly out of sight or make it jiggle about as it spins.  Since each shape needs to run an animation on its own timeline I will encapsulate this behavior in a user control.

Microsoft uses a similar technique for the Silverlight loading animation.  Watch this video of the Silverlight animation (Video 4) to see how they implemented the animation.  Note that the dots do not spin about the circle.  Instead each blue dot grows into view and then quickly disappears.

Video 4: The Silverlight animation.

 

Create the Blue Dot

As I mentioned in the last section I want to encapsulate the animated dot within a UserControl. I created the BlueDot user control in Expression Blend using the following steps.  First I added a UserControl to the project and then I added an ellipse to the main Grid.  I made the ellipse stroke invisible and changed the fill to a radial gradient brush. After fussing around with the brush for a few minutes I ended up with four gradients stops in the gradient.  Each gradient stop uses a varying degree of transparency to achieve a banded effect for the ellipse (Figure 6).

image

Figure 6: The four gradients.

The snippet below shows the finished XAML for the BlueDot ellipse.

<Ellipse Stroke="{x:Null}" x:Name="ellipse" RenderTransformOrigin="0.5,0.5">
            <Ellipse.RenderTransform>
                <TransformGroup>
                    <ScaleTransform ScaleX="0" ScaleY="0"/>
                    <SkewTransform AngleX="0" AngleY="0"/>
                    <RotateTransform Angle="0"/>
                    <TranslateTransform X="0" Y="0"/>
                </TransformGroup>
            </Ellipse.RenderTransform>
            <Ellipse.Fill>
                <RadialGradientBrush>
                    <GradientStop Color="#CA2C8DDE" Offset="0.634"/>
                    <GradientStop Color="#39FFFFFF" Offset="1"/>
                    <GradientStop Color="#CA2C64DE" Offset="0.33"/>
                    <GradientStop Color="#B56A8FDE" Offset="0.062"/>
                </RadialGradientBrush>
            </Ellipse.Fill>
        </Ellipse>

Figure 7 shows my finished UserControl.

image

Figure 7: Finished UserControl.

The Grow Animation

Now that I’ve finished the ellipse I need to design the Grow/Shrink animation.  I’ll use Scale Transform to change the size of the ellipse.  To be more precise I am animating the shape’s ScaleX and ScaleY properties.  I want the dot to grow from zero scale to full scale in roughly two seconds.  Once the dot is full size, I want it to hesitate for a short time and then quickly disappear.  Figure 8 shows my resulting timeline after experimenting in Blend.

Do you see the two keyframes at 2.0 and 2.5 seconds?  These two keyframes make the animation appear to hesitate before it shrinks from sight.  To recap: the dot grows in size for two seconds, stays at that size for 0.5 seconds and then scales back to zero in 0.5 seconds.

image

Figure 8: The four keyframes

Video 5 shows what my animation looks like.

Video 5: Grow animation.

 

Adding a Custom BeginTime Property

Now I want to show you how to control the start time of my BlueDot animation. Currently the animation starts on the Control Loaded event.  The finished circular pattern will consist of eight BlueDot controls.  If I use the control as it is currently implemented each BlueDot’s grow animation will start simultaneously. Instead I want to stagger the start time of each animation.  Adding a BeginTime dependency property to the BlueDot control allows the host container, in this example the page, to choose the start time.

I need to know the Key value for the BlueDot control.  A quick look in the XAML files shows that mine is named GrowStoryboard.  The Key value is necessary when I call FindResource to get a reference to the storyboard.

XAML

<!-- This is the main Storyboard for the grow/fade animation. -->
    <Storyboard x:Key="GrowStoryboard">

In the code behind I get a reference to the storyboard in the constructor.  Then I create the dependency property and setup a PropertyChangedCallback method.

Code Behind

public partial classBlueDot: UserControl

{

    privateStoryboard_sb;

    publicBlueDot()

    {

        InitializeComponent();

        // find the resource declared in the XAML file

        _sb = FindResource("GrowStoryboard") as Storyboard;
    }

    /// <summary>
    /// BeginTime Dependency Property
    /// </summary>
    public static readonly DependencyProperty BeginTimeProperty =
            DependencyProperty.Register("BeginTime", typeof(TimeSpan), 
                                         typeof(BlueDot),
                    new FrameworkPropertyMetadata((TimeSpan)TimeSpan.FromMilliseconds(0),
                    new PropertyChangedCallback(OnBeginTimeChanged)));

    /// <summary>
    /// Gets or sets the BeginTime property.  This dependency property
    /// indicates what time the animation should start.
    /// </summary>
    public TimeSpan BeginTime
    {
        get { return (TimeSpan)GetValue(BeginTimeProperty); }
        set { SetValue(BeginTimeProperty, value); }
    }

    /// <summary>
    /// Handles changes to the BeginTime property.
    /// </summary>
    private static void OnBeginTimeChanged(DependencyObject d, 
                         DependencyPropertyChangedEventArgs e)
    {
        ((BlueDot)d).OnBeginTimeChanged(e);
    }

    /// <summary>
    /// Provides derived classes an opportunity to handle changes to the BeginTime property.
    /// </summary>
    protected virtual void OnBeginTimeChanged(DependencyPropertyChangedEventArgs e)
    {
        _sb.BeginTime = (TimeSpan)e.NewValue;
    }
}

UserControls on the ToolBox in Expression Blend

Once you have compiled a project in Expression Blend (F5) any UserControls in the project are added to the Assets library.  To add the new BlueDot control to the ToolBox:

 

1.

Click the Asset Library button on the ToolBox.

image

2.

Click the Custom Controls button.

Choose the BlueDot control from the list of controls.

image
3. The selected control is added to the ToolBox. image

 

Putting it All Together

The final touch it to create the circular pattern with the new BlueDot control.  I just showed how to do this in the previous demo so the steps should be fresh in your mind. 

  1. Add the BlueDot control to a Window/Page.
  2. Move the CenterPoint to a new location.
  3. Make seven copies of the BlueDot control.
  4. For each copy, change the RotationTransform angle to a multiple of 45

    (0, 45, 90, 135, 180, 225, 270, 315).
  5. Add a 360-degree rotation animation to all the shapes.

Using the BeginTime property

It’s time to set the BlueDot.BeginTime property for each of the eight user controls. I can set this in the XAML but for this project I decided to use the Blend Property Pane. 

1.

Choose one of the BlueDot user controls in the Artboard.  For this example I picked the one at the 3 o’clock position.

Note: the animation will be running while viewing the items in Blend.

image

2.

In the Property pane search box type: "Begin".  The Property pane should narrow the results and only show the BeginTime property.

Set the BeginTime value to 400 milliseconds (00:00:00.4000000).

image

3. Continue setting the BeginTime property on the other BlueDots.  I choose to stagger each one 200 milliseconds from its neighbors.  

You can see the resulting XAML.

<CircularAnimations_Examples:BlueDot  Width="40"
                                      Height="40"
                                      RenderTransformOrigin="0.508,2"
                                      BeginTime='00:00:00.4'>
     <CircularAnimations_Examples:BlueDot.RenderTransform>
       <TransformGroup>
         <ScaleTransform ScaleX="1"
                         ScaleY="1" />
         <SkewTransform AngleX="0"
                        AngleY="0" />
         <RotateTransform Angle="90" />
         <TranslateTransform X="0"
                             Y="0" />
       </TransformGroup>
     </CircularAnimations_Examples:BlueDot.RenderTransform>
   </CircularAnimations_Examples:BlueDot>

Now it’s time to see the results of all this work (Video 6).  I think you’ll agree that it looks very similar to the official Silverlight animation.

Video 6: Silverlight animation recreated.

What’s Next?

That’s all I have for you.  Now you get to show your creative side.  What kinds of circular animations will you make?

Source Code and Sample Project

You can find the examples from Part 1 and Part 2 of this article in the CircularAnimation project available on the MSDN Code Gallery site.

[Source code for article is available on CodeGallery]

By default any Silverlight video you create in Expression Encoder 2 has AutoPlay set to true.  Therefore if you have a Web page with several of these Silverlight applications embedded they’ll all start playing at the same time.

Turn It Off

Figure 1:  Turn it off.

Hidden Setting in Expression Encoder 2

There is a way to configure AutoPlay in Expression Encoder. It’s just not very obvious. 

  1. Open Expression Encoder2
  2. Open an project and ensure that it contains a video. If not, Import a video.
  3. Go to the Output tab on the right hand side, and select a Template (see Figure 2).
  4. Click the Show Advanced Properties symbol.  This will open another properties pane.

image

Figure 2: Output Tab.

There are few interesting properties in this advanced section.  The two that solve the auto start problem are shown in Figure 3:

image a

Figure 3:  Job output advanced properties.

Automatically start video when cued:  Uncheck this checkbox to prevent the video for auto starting.

Automatically cue video when the page is loaded: This causes the video to be downloaded to the user computer even if playback has not started.

Multi-touch (MT) is a big part of Windows 7.   MT is exciting and opens up new choices for UI interaction but the enthusiasm will quickly fade if you don’t have a multi-touch enabled monitor.

Albatron Multi Touch

Figure 1: Albatron Multi-touch.

The good news is that there are multi-touch devices coming soon to your favorite hardware dealer.  Hardware vendors like HP, Dell and Albatron want to have their products available before the October 22nd, 2009 release of Window 7. DigitTimes reports that a number of companies will be competing for a place on your desktop.

Touch panel makers, including eTurbo Touch, Mildex Optical, and Integrated Digital Technologies (IDT), are showcasing multi-touch technology supporting Microsoft Windows 7 at the ongoing Computex 2009.

The touch panel makers are introducing improved capacitive touch panels for medium- to large-size products, with prices 50-60% more than traditional capacitive touch panels and 60-80% less than projective capacitive touch panels, according to market sources.

 

Multi-touch painting

Figure 2: Multi-touch painting.

Developing MT Applications Without a MT Device

One of the biggest obstacles in programming and testing a multi-touch (MT) application is enabling developers who don’t have MT computers to interact in a simulated MT way.

The Surface team solved this problem by creating a Surface emulator.   Since the Surface has a five camera vision system buried in the depths of the table they needed to create a emulator that mimics that camera system on a normal PC.

It’s similar if you plan on adding MT to your Windows 7 application.  For various reasons your dev team may not have MT devices for all team members.  Both testers and developers need a way simulate user touches from their legacy hardware.  Unfortunately there is no official emulator available from Microsoft.  But there is a third party work-around that solves that problem.

Multi-Touch Vista  on CodePlex to the Rescue

Multi-Touch Vista is a user input management layer that handles input from various devices (touchlib, multiple mice, TUIO etc.) and normalises it against the scale and rotation of the target window. Now with multi-touch driver for Windows 7. — http://multitouchvista.codeplex.com

The Multi-Touch Vista project on CodePlex, despite what you’d infer from the name, is intended to run under Windows 7.  It provides a multi-touch driver and services for your computer, which enables you to use multiple mice to simulate MT input in your application, even though your computer may not have a MT device attached.

Downloading MultiTouchVista

The directions on the Codeplex site are a little vague.  Here is what worked for me.

The first step is to download the latest release from the Multi-touch CodePlex site. Unzip the files into any folder on your hard drive (see Video 1).

Video 1: Downloading the project.

Installing Drivers

Windows 7 supports input from a lot of devices. There are the traditional input devices, (mouse and keyboard), tablet PC pens (stylus) and touch specific input (contacts). MultiTouchVista installs a driver that tricks Windows 7 into thinking your multiple mice are really touch contacts.  Then you can simulate applying two finger rotations to your screen entities via your two mice

Installing this driver is easy.  Find the Install Driver.cmd fill in Windows Explorer and double-click it.

Install driver.cmd

Figure 3: Install driver.cmd

To verify that the driver is installed open the Pen and Touch dialog.  The last two tabs, Touch (Figure 4) and  Panning (Figure 5) are visible if Windows detects a touch input device. 

Touch tab in settings dialog

Figure 4: Touch tab in settings dialog.

image

Figure 5: Panning tab in settings dialog.

Watch the video (Video 2) to see how to install the multi mouse drivers.

Video 2: Installing the drivers.

Starting the Necessary Services

The last step is to start the two services provided by MultiTouchVista project.  From the install folder run Multitouch.Driver.Services.exe and Multitouch.Service.Console.exe (Figure 6). 

Service and configuration applications

Figure 6: The service and configuration applications

Once the Multitouch.Service.Console.exe starts you will see a red dot on the screen for each mouse attached to your computer. In the screenshot (Figure 7) of my laptop there are three red dots.  One dot for my laptop touchpad and two dots for each of the connected mice.

image

Figure 7: The three red contact dots.

The MultiTouchVista API also provides a simple configuration tool(Multitouch.Configuration.WPF.exe) that blocks the Windows 7 native input.  Be careful, when using this utility.  If you choose this option your mice will no longer interact with any Windows 7 window.  They will work within your touch enabled WPF application but  not on the rest of the Window UI.
This last video shows how to start these services (Video 3).

Note:  The audio encoding for this is distorted.  I will encode again and repost.

Video 3: Starting the services.

Virtual PC and MultiTouchVista

I tested MultiTouchVista on a couple Windows 7 images running on Virtual PC and it doesn’t work.  I’m guessing that is due to the way VPC handles multiple mouse input.  I also attempted to test on Sun’s Virtualbox but I couldn’t install Windows 7 RC on the Virtualbox drive image.

Part One

A common UI metaphor in recent times is the circular wait cursor or progress indicator. This article shows some easy techniques within Expression Blend 2 that simplify creating this modern UI indicator. After showing how to easily layout multiple child elements in a 360-degree pattern, I will show animation techniques for spinning, sizing and fading sub-elements.

[Source code for article is available on CodeGallery]

Keeping Them Happy While Waiting

It’s a bad idea to start a long running task in your application and not provide concrete feedback to the user. If the user doesn’t know that you started downloading their requested file they will eventually click the download button again. To avoid this you must let them know that their work is under way.

At the minimum, you must alert them that the process has started. This immediate feedback is important to reassure the user that they did the right thing, plus it prevents multiple initiations of the process.

Additionally it is nice if you can convey how long the process will take. This permits the user to make an intelligent decision about what to do next. A coffee break might in order if I know that it’s going to take twenty minutes before I can install the downloaded file.

Finally, providing progress details can be beneficial. If you can display accurate information regarding the amount of time left before the task is finished, so much the better.

Ever since the first UI framework emerged, there have been attempts to provide standardized feedback to the end user. It has taken many forms over the past few decades.

Wait UI

Wait Cursor: One of the earliest attempts at user notification was the wait cursor, which an application would enable upon starting a task. The classic wait cursor is the hourglass or clock face. While this cursor is handy at letting the consumer know that the task has started it provides no other useful information.

ProgressBar: You’ve seen progress bars in action. These simple controls provide a lot of information to the end user. At a glance, you can see the task has started and how much of the task remains to be accomplished. Some versions of the progress bar shows informative text (example: 3 of 12 items downloaded) to provide even more details.

Wait UI in this Century

Change is a constant in the software industry. We are always on the lookout for a better, cleaner, prettier way to accomplish a given task. In the last couple years the circular animation has become a popular way to show wait UI.

Take Windows Vista for example. The busy cursor has morphed from an hourglass into a blue ring with an animated highlight buzzing ceaselessly about the blue band.

VistaBusyCursor 

 

The Vista Sync Center sports a new icon that spins in the system tray. One glance at the arrows whirling about in the system tray tells you that your handheld device is synchronizing with your desktop.

Sync

 

The Web world has its share of circular eye candy too. Let’s turn to Silverlight for an example. When your browser encounters a Silverlight application it has to download the application XAP file to your local computer. Naturally during this process the Silverlight runtime displays its version of the ubiquitous 360-degree animation.

image

 

A couple of noteworthy items to observe with this animation. First, observe the progress text centered within the animation. Since the animation itself doesn’t provide progress information, the progress text is a useful addition. Second, this animation appears to be more of a pulsing action rather than a spinning action. It does this by making each blue dot grow larger and then suddenly hiding the dot. Each dot in the circle starts animating at a different time with the start time staggered around the circle. This animation is subtle yet curiously satisfying to watch.

Implementing a Circular Animation

In this article, I will show you how to create animations similar to the previous examples. I will use Expression Blend to create the WPF assets and animations. While all the demos are in WPF, rest assured that you could create Silverlight animations in nearly the same way.

Let us start by looking at the Vista busy cursor (see the following video). If you scrutinize this cursor, a few things are apparent. The UI consists of two circles. The center circle is white (or transparent) and is smaller than the outer circle. The outer circle is filled with a linear gradient that is light blue on the top and bottom and dark blue in the center. It also looks like there is a blue border on both circles.

Now watch the spinning animation. You should note that the gradients don’t appear to move. Instead, it looks like there is a semi-transparent ellipse that is superimposed over the band. This implies that it is the ellipse that is moving, not the underlying circles.

 

Vista Aero Busy

Now that you have a basic idea of the parts that make up the animation it’s time to open Expression Blend and make one for yourself.

The Basic Band

To get warmed up for the upcoming Blend design marathon you will start with a simple band animation.

1. Open Expression Blend.  

2.

Create a new project. I’m going to name mine CircularAnimation.

 

3.

Create a new container for the animation. It could be a Window, Page or UserControl. For my example I’m using a Page.

 
4. Add an Ellipse to the Artboard. Choose the Shape palette on the Toolbox. image

5.

Hold the Shift-key while drawing the Ellipse in the Artboard. This constrains the Ellipse to a circle.

 

6.

Change the Fill color.

  1. In the Property window choose the Brushes section.
  2. Click the Fill button, then the ‘No Brush’ button.
image

7.

Change the Ellipse border.

  1. Click the Stroke button.
  2. Click the GradientBrush button.
  3. The default colors are white and black for the gradient. Select each color selector in the color bar and choose an attractive color.
  4. Change the StrokeThickness to 12.
image

 

Admire your ring before moving to the next step. 

Animate the Band

In this step you will animate the ring 360 degrees.

1. Add a storyboard to the page.  

2.

In the Objects and Timeline window click the Add (+) button.

Add a timeline

3.

Choose a name for the storyboard.  I left mine at the default of "Storyboard1".

Name the storyboard
4. In the Objects and Timeline Panel, click at the two second mark. Click the 2 second mark
5. Choose the Transform section in the Property pane. Now you need to specify a 360 rotation.  Since the default value for a RotateTransform is 0 degrees, you must be careful to specify an ending value of 359 degree to make the animation look correct. Rotate Transform
     

That’s all for now.  Press F5 to run the application and watch the colors spin once about the circle. It should look similar to the following video.

Spinning Ring

Creating the Vista wait cursor

The key concept in this next demonstration is understanding how to spin a small ellipse around a center point. With a few rudimentary math skills you can make a circle move in an orbit about a central body. If you master one simple Expression Blend trick, however, you can be an ‘orbit’ master without writing a single line of code.

Create the Starter Ellipse

To start this section you will create another page and basic animation similar to the previous demonstration.

1.

Add a new Page to the demo application. Use the Project menu to change the startup item to your new item. For Example, in the accompanying screenshot I am changing the Startup item to MainWindow.xaml.

image

2.

Add a new Ellipse (circle) to the page. Create a 360 rotation animation similar to the one you created in the previous demo.

 

 

The Gradient Trick

Are you ready to master the orbiting gradient trick?

Applying a transform to a radial gradient brush is the secret sauce that makes this trick work. If you do it the right way you can mimic a small circle that is positioned on the edge of the real ellipse.

1.

Create the Gradient

 

2.

Select the ellipse and change the fill to a RadialGradient. image

3.

Choose a color for the first gradient stop.  Make the other gradient stop the same color.

image

4.

Click the gradient bar to add another gradient stop.

image

5.

To simulate a border make the middle gradient stop black.  Then change the right-most gradient stop to transparent.  You accomplish this by setting its alpha channel to zero.

 

6.

Move the gradients stops so that they are arranged similar to the accompanying screen shot. image
7. Your ellipse should look something like this. image 

 

Brush Transform Tool

Blend contains a marvelous aid called the Brush Transform tool, that simplifies the editing of your tile or gradient brushes.  I’ve written about this tool before (Constraining the Brush Transform ToolUsing a TileBrush in Expression Blend).  Using this tool you will move the gradient to the upper-right corner of the containing ellipse. 

1.

Choose the Brush Transform tool from the Toolbox.

image

2.

Select your ellipse.

Drag one of the corner handles to scale the gradient.

image

3.

Shrink the gradient and move it to the upper right corner of the containing ellipse.

image
4.

Notice that you cannot see the entire gradient. Move the gradient back into the body of ellipse.

image

That’s it.  You are finished. Since you already animated the ellipse earlier in this demo you can run the application and watch the animation.

Here is what the animation should look like when you are finished.

Animated Gradient

Simulate Movement Around a Track

Take a look at the Vista busy cursor video again. Do you see that the white spot is moving around the outside band? You can simulate that effect by using the technique you just learned. You will need to add a border to your ellipse and apply a gradient fill to the border but that is not difficult.

The animation consists of three ellipses all centered on the same point. 

1. Add another page to your project.  
2. Add three ellipses to the page.  Make all three the same size and in the same location.  Name them as shown in the accompanying screenshot (Outer, Center, Highlight). image
3. Change the Scale of the Center ellipse to 0.7.  
4. This is what the finished ellipses look like.  Examine the sample project file for more details.  

5.

Highlight: A semi-transparent white gradient created using the previous ‘Brush Transform tool’ technique.  Notice that the ellipse is not circular and is wider than it is tall. image

6.

Outer: An outer circle filled with a linear gradient fill. image

7.

Center: A smaller white circle with black border image

8.

The finished graphic should look similar to the following. image

 

Then you apply a 360-degree animation to the Highlight ellipse and you are done. This is getting closer to our goal of looking like the Vista busy cursor.  It’s a bit crude, and it still needs some work but it is close enough for our purposes.

I’ve included a completed sample project (CircularAnimation.zip) for you to explore and learn more about how these animations are constructed.

[Source code for article is available on CodeGallery]

What’s Next?

In part two of this article I will show you how to arrange elements evenly about the perimeter of a circle and how to recreate the Silverlight loading animation.

Show off your superb Silverlight skills and win $10,000 USD.  

http://www.componentart.com/community/competition2009/

 

ComponentArt is excited to host the 2009 Summer Silverlight Coding Competition and award $10,000 USD to the author of the best application as selected by our expert panel and the community. Authors of the two runner-up applications will each receive ComponentArt licenses (a $1,299 USD value).

Dig through the .NET class libraries for a few minutes and you’ll find collections (islands) of static data. For example, the Fonts class exposes two static properties, Fonts.SystemFontFamilies and Fonts.SystemTypefaces, which are useful for enumerating the installed fonts on the system. In this tip, I’ll show you how to list font families in WPF by filling a ListBox with the FontFamilies data.

Binding to Static Data

WPF has a special markup extension for retrieving static data. Markup extensions are classes that are called by WPF at runtime to provide a way to access static properties. Any public static field or property can be used via the x:Static markup extension. For instance, the following code snippet shows a class with a static property:

class Document {
  // defines a static property or field
  public static double DocumentWidth { get; set; }
}

The XAML snippet to retrieve the static DocumentWidth property would be:

<Grid>
  <!-- assumes you have a xmlns:local declaration pointing to the
      assembly containing the Document class -->
  <RichTextBox Width='{x:Static local:Document.DocumentWidth}' />
</Grid>

Binding to FontsFamily property

Now that you understand the x:Static markup extension, let’s see how to bind a ListBox to a static collection.

<!-- DataContext specifies the binding source
     for any bindable property in the ListBox or its children.
     ItemsSource specifies the source of list data
     In this example the ItemsSource is bound to the DataContext data
     -->
 <ListBox DataContext="{x:Static Fonts.SystemFontFamilies}"
  ItemsSource='{Binding}'
  HorizontalContentAlignment='Stretch'>

 </ListBox>

ListBox showing plain fonts

As you can see from the screen shot, the ListBox is filled with the font data. This font list is serviceable, but it’s also boring. You’ve probably seen font lists in other applications that preview the font by as showing the font name in the actual font. Data templates are the key to creating this type of UI in bound lists.

Data Templates

A data template is an alternate UI for your application data. When WPF attempts to render your data, it checks to see if there is a template available. If so, the template is expanded and applied to your data prior to rendering to the screen. In the next example, a data template is assigned to the ListBox ItemTemplate. Note that while this template is declared within the ListBox element, it could also be placed in the Window.Resources section.

<ListBox.ItemTemplate>
        <!-- Apply a template to each Item in listbox -->
    <DataTemplate>
    <!-- DataTemplate is affliated with the bound data.
    in this case the FontFamiles property-->
    <Border Padding="5"
        Margin='0,5'
        BorderBrush='LightBlue'
        CornerRadius='4'
        BorderThickness='4'>
    <StackPanel Orientation='Vertical'>
    <TextBlock VerticalAlignment='Center'>
    <!-- ContentPresenter is the placeholder in the template
    where the bound data should be rendered.
    In this case, I'm placing it within
    this TextBlock -->
    <ContentPresenter Content="{TemplateBinding Content}" />

    </TextBlock>
    <!-- use the bound data to set the FontFamily
    for this TextBlock -->
    <TextBlock FontFamily='{Binding Source}'
        VerticalAlignment='Center'
        Margin='20,3'
        Foreground='DarkGray'>ABC DEF GHI JKL MNO PQR STU VWYZ
    </TextBlock>
    </StackPanel>
    </Border>
    </DataTemplate>

    </ListBox.ItemTemplate>

</ListBox>

The ListBox should now look like this:

ListBox showing WYSIWYG fonts

[Original article on TechTarget.com]

Erno de Weerd has released a plug-in for Windows Live Writer that simplifies inserting a Silverlight application into your WordPress blog post.  It’s works in conjunction with Tim Heuer’s Silverlight WordPress plug-in.

It Works for Me

I installed the plug-in today and it seems to work as advertised.   I’ve added a animated Silverlight scene to this post via the plug-in.  It only took a few seconds to insert the Silverlight app.  Nice!

If you have Silverlight 2 installed you should see it below. 

The plug-in defaults to placing your XAP file in a folder (on the web server) based on year and month.  This location is suppose to be configurable but I haven’t figured out how to show the configuration screen for the plug-in yet.

image

 

The Embedded Silverlight Application

This is an example from an future series about Silverlight animation.

Install Microsoft Silverlight

Jaime Rodriquez posted a must read article regarding the Silverlight 3 PlaneProjection feature.

Silverlight3 introduces a new Projection property on UIElement.   The property is of type Projection (an abstract class). In SL3, the only implementation of Projection class is PlaneProjection, which is an implementation of a 3D PerspectiveTransform. As of SL3 beta1, the implementation is software-based (so not hardware accelerated today).
The UIElement that is projected into this 3D scene is interactive even if projected. Both front and back are interactive.

Customers have been requesting 3D support for Silverlight since the first public previews back at 2006.   While Silverlight will not have true 3D the pseudo 3D  provided by PlaneProjection is good enough for many scenarios.

PlaneProjection = Transforms + 3D scene
For me, it is easiest to think of PlaneProjection as a wrapper for a 3D scene and series of 3D Transforms that you can apply to a UIElement to get it to ‘project’ in 3D space.

The transforms that PlaneProjection applies to its UIElement are: 

  1. A TranslateTransform exposed via LocalOffsetX, LocalOffsetY, LocalOffsetZ in PlaneProjection.
  2. A set of RotateTransform   represented by the CenterOfRotationX, CenterOfRotationY and CenterOfRotationZ  and the RotationX, RotationY an RotationZ properties.
  3. A TranslateTransform(3D), exposed via GlobalOffsetX, GlobalOffsetY, GlobalOffsetZ

Older Posts »