Click here to Skip to main content
15,896,421 members
Articles / Desktop Programming / WPF

A framework for comprehensive validation of user input

Rate me:
Please Sign up or sign in to vote.
4.70/5 (8 votes)
19 Jun 2012CPOL28 min read 31.3K   523   18  
Validation of input made as easy as possible for Windows.Forms, WPF, console-applications or any other purposes
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Ganzer.Wpf.Validation;
using Ganzer.Wpf;

namespace WpfValidatorTutorial.Mvvm
{
	//############################################################################
	/// <summary>
	/// The GenericDialog class defines a container for views that shall be shown
	/// as a modal dialog with "OK" and "Cancel" buttons.
	/// </summary>
	/// 
	public partial class GenericDialog : Window
	{
		#region initialization

		/// <summary>
		/// Initializes this object.
		/// </summary>
		/// 
		public GenericDialog()
		{
			InitializeComponent();
		}

		#endregion

		#region event handling
		#region GenericDialog

		/// <summary>
		/// Called when the window is initialized.
		/// </summary>
		/// 
		/// <param name="e">The event arguments.</param>
		/// 
		/// <remarks>
		/// Removes the symbol and the minimize and maximize buttons from the title.
		/// </remarks>
		/// 
		protected override void OnSourceInitialized( EventArgs e )
		{
			this.RemoveDecorations(WindowDecorations.Icon);
			base.OnSourceInitialized(e);
		}

		#endregion
		#region controls

		/// <summary>
		/// Called when the OK button is clicked.
		/// </summary>
		/// 
		/// <param name="sender">The sender of the event.</param>
		/// <param name="e">The event arguments.</param>
		/// 
		/// <remarks>
		/// Commits the input and closes the dialog after it is successfully validated.
		/// </remarks>
		/// 
		private void _btnOK_Click( object sender, RoutedEventArgs e )
		{
			//
			// Check whether the input is valid:
			//
			if( ValidationService.ValidateGroup(_content) )
			{
				BindingGroup.CommitEdit();
				DialogResult = true;
			}
		}

		#endregion
		#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
Germany Germany
I am a software developer since many years and have worked on several large projects especially in financial sectors and the logistics industry.

My favorite programming languages are C, C++ und newly C#.

I am the architect and chief developer of Tricentis TDM Studio (former Q-up) - a generator that primarily creates template based synthetic data for software testing.

Comments and Discussions