Click here to Skip to main content
15,885,278 members
Articles / Desktop Programming / WPF

Extending the WPF Calendar Control

Rate me:
Please Sign up or sign in to vote.
4.84/5 (28 votes)
10 Sep 2010CPOL26 min read 154.9K   5K   65  
This article shows how to create a custom control that extends an existing WPF control. It extends the WPF Calendar control by adding date highlighting.
using System;
using System.Globalization;
using System.Windows.Data;

namespace FsControls
{
	public class HighlightDateConverter : IValueConverter
	{
		#region Properties

		/// <summary>
		/// The FsCalendarControl that owns this converter.
		/// </summary>
		public static FsCalendar Parent { get; set; }

		#endregion

		#region IValueConverter Members

		/// <summary>
		/// Converts from a Date Dictionary to a String.
		/// </summary>
		public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
		{
			// Exit if highlighting turned off
			if (Parent.ShowDateHighlights == false) return null;

			// Initialize
			var dateDictionary = Parent.HighlightedDates;
			var targetDate = (DateTime) value;

			// Get tool tip for date passed in
			string toolTip = null;
			var dateIsHighlighted = dateDictionary.ContainsKey(targetDate);
			if (dateIsHighlighted) toolTip = dateDictionary[targetDate];

			// Set return value
			return toolTip;
		}

		/// <summary>
		/// Not used.
		/// </summary>
		public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
		{
			return null;
		}

		#endregion
	}
}

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)


Written By
Software Developer (Senior) Foresight Systems
United States United States
David Veeneman is a financial planner and software developer. He is the author of "The Fortune in Your Future" (McGraw-Hill 1998). His company, Foresight Systems, develops planning and financial software.

Comments and Discussions