03.31.07

Building a Simple WPF Animation

Posted in WPF, WPF Animations at 6:19 am by Cal

This project illustrates a very simple WPF animation. The source code for this project is available here . If you prefer just the executable file itself, it is available here .

Cal With Glow

This project is a WPF Windows application (not an XBAP or WPF/E). I used Expression Blend to build it since animation in Blend is a much simpler task than it is in Visual Studio. The first thing which I did was to rename Window1 to MainWindow since using default names is only acceptable in a throw away project. Other minor housekeeping tasks included adding a custom icon to both the project and the MainWindow. In both cases, all that is required is to set the Icon property to the relative path of the icon file. (images/iconfile.ico)

Of course, the icon file should be added to the project. Be sure to set the Build Action of any image file to Resource — NOT Embedded Resource. A good way to remember that is to “avoid the ER” since you probably wouldn’t enjoy it there anyway. The Embedded Resource setting is used for Windows Forms projects and will not work with WPF images.

Resource Build Action

This animation uses two photographs taken at the Chernobyl nuclear reactor in the Ukraine (about 90 miles north of Kiev). Actually, both photographs are just the same photograph, one of which has been dressed up in Photoshop to include the glow effect. Any image file that you want to use in a WPF application should be explicitly added to your project. This can be done in either Blend or Visual Studio. It is generally best to create a new folder named “images” and then place all the image files that you need into that folder. To later reference any such files all you need to do is to include the folder name in the path (eg. images/filename.jpg).

Adding Images to the Images Folder

When you place two elements in a WPF Grid and you do not specify any rows or columns, both elements simply sit on top of each other in the same cell. Knowing this, I positioned my photographs so that the one without the glow sits directly in front of the one with the glow. Whichever element is added later will have the highest Z-Order.

Two Elements in the Same Grid Cell

Using the Animation Workspace in Blend I set a keyframe at time 02. At the beginning of the timeline, the opacity of the front photograph starts out at 100%. This means that when the application begins to run, the front photo is fully opaque. At the 2 second mark (the first keyframe), I set the opacity of the front photo to 0%. At this point, the front photo is entirely translucent and a user will see only the rear photo — the one with the glow. Then I created a second keyframe at time 00:00:04 (4 seconds). where I set the opacity of the first photo back to 100%. Animations of this sort scale in a linear fashion, meaning that at the 1 second point as well as the 3 second point, the opacity of the front photo will be 50%.

Animation Keyframe

WPF animations are not affected by CPU speed. A faster CPU will mean a smoother animation not a shorter animation.

Next I set AutoReverse to True and RepeatBehavior to Forever. This makes the glow fade back out and then reappear indefinitely until the user closes the application. Technically, I didn’t have to set AutoReverse to True since the animation as I built it already performs a complete cycle from 100% opaque to 100% transparent and back to 100% opaque again. If I had stopped the animation when the front photo was fully transparent, the AutoReverse setting would have been required in order to return the front photo to opaque.

Automation Properties

To allow the photo without the glow to appear briefly before the glow starts to phase in, I set the BeginTime property of the animation to 2 seconds (00:00:02). The BeginTime property is used to delay the commencement of an animation for a specified period of time. (2 seconds in my case as shown in the illustration above)

The triggering event is the loading of the MainWindow.
Trigger on Window Load

So as you can see, the steps required to create this animation are actually very simple. Not including the time needed to fly to the Ukraine to take this photo or the time needed to fix it up in Photoshop, buiding this animation can easily be accomplished in under half an hour.

03.30.07

Free Microsoft Software

Posted in Free Software, MSDN Academic Alliance at 11:03 pm by Cal

Visual Studio 2005
Foothill College participates in the MSDN Academic Alliance program. Under this program students enrolled in any CTIS class can acquire Microsoft software for only a small administrative fee.This program covers software for developers: Visual Studio 2005 Professional and Team Suite Editions, SQL Server 2005, Windows Server 2003 Enterprise Edition, SharePoint Server, etc.

All of this software is full featured, non-time out software. When you are no longer a student at Foothill College you are not required to uninstall the software.

The only limitation is that since this software is subject to Academic licensing, you are not permitted to use this software for commercial purposes. It is, however, perfect to use to learn any new technology at an affordable cost.

03.29.07

My First Post — Classes at Foothill College!

Posted in Classes, Foothill at 10:18 pm by Cal

I named this Blog the WPF Learning Experience because I wanted its focus to be on learning WPF technology. I teach what I believe to be the first college class on WPF in California (possibly in the country and even possibly even world wide). The first pass through this class was so enjoyable and so exciting that I’m looking forward to many, many more.

Here’s a comment from one of my students sent to me by Email a couple of weeks ago:

“This class is teaching something too valuable so I convinced my manager to let me take the week off to catch up and finished this project.”

It’s always nice to hear something like that!!

And here’s a comment from another student:

Thank you so much for offering this WPF class in this fairly early stage of the technology. WPF is fantastic, although the learning curve is high.

And this:

Even more, I feel WPF is so important that I am continuing on my own writing WPF/Xaml code to allow the knowlege that I have acquired from your course to mature so that I may demonstrate it to others.

The next WPF class starts on April 9th and is offered both as a regular face to face class an online.

I’m sort of the unofficial head of the C# department (well actually more like a sub-sub-department) at Foothill College in Northern California. As such, I try to recruit students not only for my own classes but also for my colleagues who teach C# classes with me. It’s really wonderful working with Steve Hoyle, Evan Lim and John Berry on C#.

Here’s a listing of all the C# related classes that we are offering this term:

Windows Presentation Foundation (WPF) (CIS-019M)
Learn how to create exciting new user interfaces for Windows applications using WPF. Master dependency properties, routed events, styles, templates, and animations.

Windows Communication Foundation (WCF) (CIS-019L)
Learn how to build connection-based service-oriented architectures (SOAs) using Windows Communications Foundation and the textbook “Programming WCF Services” by software legend Juval Lowy.

Deploying .NET Applications (CIS-019N)
Learn how to deploy .NET applications (both Windows and Web) using Microsoft Installer, MSBuild and ClickOnce technologies. Covers initial installations, service packs, patches, and other updates.

Develop Web Applications using ASP.NET 2.0 (CIS-019W)
Learn to build dynamic websites using Visual Studio and a powerful set of Internet-related classes in the .NET Framework 2.0.

Develop Windows Forms Applications with .NET 2.0 (CIS-019D)
Learn to build traditional Windows Forms applications including those using database access.

Introduction to Programming in C# (CIS-019A)
An introductory level class to acquaint students with the fundamentals of programming console and Windows applications using C#.

Foothill KCI Building
Foothill College is located in Los Altos Hills, CA near San Jose. However, all of these classes are also offered in an online format and can therefore be taken from anywhere.The cost for California residents is under $100 per class (more for non-residents).For additional details and a live preview of the online classes, see http://www.schrotenboer.com/foothill/csharp.htm