Click here to Skip to main content
13,147,050 members (62,824 online)
Click here to Skip to main content

Stats

727.6K views
34K downloads
786 bookmarked
Posted 31 Mar 2007

A Guided Tour of WPF – Part 1 (XAML)

, 19 Apr 2007
A guided tour of the Windows Presentation Foundation, one feature at a time.
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;

namespace WpfHorseRace
{
	#region DoubleToIntegerConverter

	[ValueConversion( typeof( double ), typeof( int ) )]
	public class DoubleToIntegerConverter : IValueConverter
	{
		public object Convert( object value, Type targetType, object parameter, CultureInfo culture )
		{
			return (int)(double)value;
		}

		public object ConvertBack( object value, Type targetType, object parameter, CultureInfo culture )
		{
			throw new NotSupportedException( "Cannot convert back" );
		}
	}

	#endregion // DoubleToIntegerConverter	

	#region RaceTrackWidthConverter

	/// <summary>
	/// Determines how wide a RaceHorse's progress indicator should be, based on how far into the race it is.
	/// </summary>
	public class RaceHorseProgressIndicatorWidthConverter : IMultiValueConverter
	{
		public object Convert( object[] values, Type targetType, object parameter, CultureInfo culture )
		{
			int percentComplete = (int)values[0];
			double availableWidth = (double)values[1];
			double width = Math.Floor( availableWidth * (percentComplete / 100.0) );
			// Reduce the final width by a little bit to avoid a minor rendering overlap.
			return percentComplete == 100 ? width - 4 : width;
		}

		public object[] ConvertBack( object value, Type[] targetTypes, object parameter, CultureInfo culture )
		{
			throw new NotSupportedException( "Cannot convert back" );
		}
	}

	#endregion // RaceTrackWidthConverter	
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Josh Smith
Software Developer (Senior) Black Pixel
United States United States
Josh creates software, for iOS and Windows.

He works at Black Pixel as a Senior Developer.

Read his iOS Programming for .NET Developers[^] book to learn how to write iPhone and iPad apps by leveraging your existing .NET skills.

Use his Master WPF[^] app on your iPhone to sharpen your WPF skills on the go.

Check out his Advanced MVVM[^] book.

Visit his WPF blog[^] or stop by his iOS blog[^].

See his website Josh Smith Digital[^].

You may also be interested in...

Pro
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170915.1 | Last Updated 19 Apr 2007
Article Copyright 2007 by Josh Smith
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid