Posted by: Zeeshan Amjad | October 31, 2009

Duration class in WPF


WPF defines one class named Duration in System.Windows namespace. This class is mostly used in animation. Before WPF .Net class library already has one class TimeSpan and this class looks like a wrapper on TimeSpan class. The reason to define this class is that this class that this class define two additional properties Automatic and Forever.Here is a class diagram of Duration class.

Duration_01

Here is a class diagram to represent the relationship between Duration and TimeSpan class.

Duration_02

WPF also define one type convertor for duration class named DurationConverter to use this class in XAML. Here is a class diagram of DurationConverter class.

Duration_03

If we add Duration.Forever with Duration.Forever then its result will be Duration.Forever, however if we subtract it then its result would be Duration.Automatic. Here is a simple program to demonstrate all combinations.

  1: using System;
  2: using System.Windows;
  3: 
  4: namespace DurationSample
  5: {
  6:     class Program
  7:     {
  8:         static void Main(string[] args)
  9:         {
 10:             Console.WriteLine(Duration.Forever + Duration.Forever);
 11:             Console.WriteLine(Duration.Forever - Duration.Forever);
 12:             Console.WriteLine(Duration.Automatic + Duration.Automatic);
 13:             Console.WriteLine(Duration.Automatic - Duration.Automatic);
 14:             Console.WriteLine(Duration.Automatic - Duration.Forever);
 15:             Console.WriteLine(Duration.Forever - Duration.Automatic);
 16:         }
 17:     }
 18: }
 19: 

Here is the output of this program.

Forever

Automatic

Automatic

Automatic

Automatic

Automatic

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: