Click here to Skip to main content
15,891,136 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.9K   18.1K   76  
Login Overlay for WPF applications with a styling similar to the Windows 8 Login Screen.
using System.Windows;
using System.Windows.Controls;
using SmartLoginOverlayDemo.Models;
using SmartLoginOverlayDemo.ViewModels;
using SoftArcs.WPFSmartLibrary.SmartUserControls;

namespace SmartLoginOverlayDemo.Views
{
	public partial class MainWindow
	{
		#region Fields

		public LoginViewModel ViewModel;

		#endregion

		#region Constructor

		public MainWindow()
		{
			InitializeComponent();

			this.ViewModel = new LoginViewModel();
			this.DataContext = this.ViewModel;
		}

		#endregion

		#region Event handler

		//+--------------------------------------------------------------------
		//+ Just for demo purposes - only to demonstrate code behind handling -
		//+--------------------------------------------------------------------
		private void btnLock_Click(object sender, RoutedEventArgs e)
		{
			this.SmartLoginOverlayControl.Lock();
		}

		private void btnChangeUser_Click(object sender, RoutedEventArgs e)
		{
			this.ViewModel.ChangeRecentUser( new User()
															{
																UserName = "BlueHairBeauty",
																Password = "blue1",
																EMailAddress = @"blue@reallypretty.com",
																ImageSourcePath = @"\Images\DemoUser1.png"
															} );

			this.SmartLoginOverlayControl.DisappearAnimation = DisappearAnimationType.MoveAndFadeOutToTopSimultaneous;
			this.SmartLoginOverlayControl.Lock();

			(sender as Button).IsEnabled = false;
		}

		// ReSharper disable UnusedMember.Local
		// ReSharper disable UnusedParameter.Local
		private void SmartLoginOverlay_SubmitRequested(object sender, RoutedEventArgs e)
		// ReSharper restore UnusedParameter.Local
		// ReSharper restore UnusedMember.Local
		{
			if (this.ViewModel.Password.Equals( this.ViewModel.UserPassword ))
			{
				this.SmartLoginOverlayControl.Unlock();
			}
			else
			{
				this.SmartLoginOverlayControl.ShowWrongCredentialsMessage();
			}
		}

		#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