Click here to Skip to main content
15,893,486 members
Articles / Desktop Programming / Windows Forms

User Settings Applied

Rate me:
Please Sign up or sign in to vote.
4.95/5 (136 votes)
5 Sep 2013CPOL10 min read 544.2K   7.5K   490  
Simplifying the .NET User Configuration for Windows Forms and WPF
// -- FILE ------------------------------------------------------------------
// name       : DerivedSettingsWindow.cs
// created    : Jani Giannoudis - 2008.04.30
// language   : c#
// environment: .NET 3.0
// --------------------------------------------------------------------------
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using Itenso.Configuration;

namespace Itenso.Solutions.Community.ConfigurationWindowsDemo
{

	// ------------------------------------------------------------------------
	public partial class DerivedSettingsWindow : BaseWindow
	{

		// ----------------------------------------------------------------------
		public DerivedSettingsWindow()
		{
			// save all window textbox values to the settings using the class property
			WindowSettings.SettingCollectors.Add( 
				new PropertySettingCollector(
					this,              // owner
					typeof( TextBox ), // element type
					"Text" ) );        // element property

			// save all window cehckbox values to the settings using the dependency property
			WindowSettings.SettingCollectors.Add( 
				new DependencyPropertySettingCollector( 
					this,                           // owner
					ToggleButton.IsCheckedProperty ) ); // dependency property

			InitializeComponent();
		} // DerivedSettingsWindow

		// ----------------------------------------------------------------------
		protected override void OnCollectingSetting( SettingCollectorCancelEventArgs e )
		{
			FrameworkElement frameworkElement = e.Element as FrameworkElement;
			if ( frameworkElement == null )
			{
				return;
			}

			// exclusion rules
			if ( Option3.Name.Equals( frameworkElement.Name ) || Edit3.Name.Equals( frameworkElement.Name ) )
			{
				e.Cancel = true;
			}
		} // OnCollectingSetting

	} // class DerivedSettingsWindow

} // namespace Itenso.Solutions.Community.ConfigurationWindowsDemo
// -- EOF -------------------------------------------------------------------

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)
Switzerland Switzerland
👨 Senior .NET Software Engineer

🚀 My Open Source Projects
- Time Period Library 👉 GitHub
- Payroll Engine 👉 GitHub

Feedback and contributions are welcome.



Comments and Discussions