Click here to Skip to main content
15,888,088 members
Articles / Desktop Programming / WPF

Smart WPF Login Overlay (Windows 8 Style)

Rate me:
Please Sign up or sign in to vote.
5.00/5 (23 votes)
3 Dec 2012CPOL12 min read 134.6K   18.1K   76  
Login Overlay for WPF applications with a styling similar to the Windows 8 Login Screen.
//	------------------------------------------------------------------
//		Member of the WPFSmartLibrary
//		For more information see : (coming soon ...)
//		(by DotNetMastermind)
//
//		filename		: BooleanConverter.cs
//		namespace	: SoftArcs.WPFSmartLibrary.ValueConverter
//		class(es)	: BoolToBrushConverter
//						  BoolToOppositeBoolConverter
//
//	------------------------------------------------------------------
using System;
using System.Globalization;
using System.Windows.Data;
using System.Windows.Markup;
using System.Windows.Media;

namespace SoftArcs.WPFSmartLibrary.ValueConverter
{
	/// <summary>
	/// Converts a Boolean value into a Brush (and back)
	/// The Brushes for the true value and the false value can be declared separately
	/// </summary>
	[ValueConversion( typeof( bool ), typeof( Brush ) )]
	[MarkupExtensionReturnType( typeof( BoolToBrushConverter ) )]
	public class BoolToBrushConverter : MarkupExtension, IValueConverter
	{
		/// <summary>
		/// TrueValueBrush (default : MediumSpringGreen => see Constructor)
		/// </summary>
		public Brush TrueValueBrush { get; set; }

		/// <summary>
		/// FalseValueBrush (default : White => see Constructor)
		/// </summary>
		public Brush FalseValueBrush { get; set; }

		/// <summary>
		/// Initialize the 'True' and 'False' Brushes with standard values
		/// </summary>
		public BoolToBrushConverter()
		{
			TrueValueBrush = Brushes.MediumSpringGreen;
			FalseValueBrush = Brushes.White;
		}

		#region IValueConverter Members

		public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
		{
			if (value is bool)
			{
				return (bool)value ? TrueValueBrush : FalseValueBrush;
			}

			return value;
		}

		public object ConvertBack(object value, Type targetType, object parameter,
										  CultureInfo culture)
		{
			if (value is Brush)
			{
				return value.Equals( TrueValueBrush );
			}

			return value;
		}

		#endregion // IValueConverter Members

		#region MarkupExtension "overrides"

		public override object ProvideValue(IServiceProvider serviceProvider)
		{
			return new BoolToBrushConverter
						 {
							 TrueValueBrush = this.TrueValueBrush,
							 FalseValueBrush = this.FalseValueBrush
						 };
		}

		#endregion
	}

	/// <summary>
	/// Converts a Boolean value into an opposite Boolean value (and back)
	/// </summary>
	[ValueConversion( typeof( bool ), typeof( bool ) )]
	[MarkupExtensionReturnType( typeof( BoolToOppositeBoolConverter ) )]
	public class BoolToOppositeBoolConverter : MarkupExtension, IValueConverter
	{
		#region IValueConverter Members

		public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
		{
			if (value is bool)
			{
				return !(bool)value;
			}

			return value;
		}

		public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
		{
			if (value is bool)
			{
				return !(bool)value;
			}

			return value;
		}

		#endregion

		#region MarkupExtension "overrides"

		public override object ProvideValue(IServiceProvider serviceProvider)
		{
			return new BoolToOppositeBoolConverter();
		}

		#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
Architect SoftArcs
Germany Germany
Experience:
More than 20 years with software design, architecture and development. More than 9 years with the .NET Framework.

Preferences:
C#, .NET 2.0, .NET 3.5, .NET 4.0, .NET 4.5, WPF (3, 4 and 4.5), MVVM, XAML, Silverlight, Windows Phone, Windows 8 Apps, ASP.NET, WCF, T-SQL and especially GUI-Development and GUI-Design.

I would say I am a dotNet Developer with a keen affinity for developing and enriching user interfaces.

Comments and Discussions