Click here to Skip to main content
15,897,704 members
Articles / Programming Languages / C#

Simple databinding with XML - A GUI for configuration files

Rate me:
Please Sign up or sign in to vote.
4.81/5 (29 votes)
2 Feb 20049 min read 130.3K   1.3K   78  
This article is about using simple databinding on XML documents by using strongly typed XML documents generated at runtime, taking advantage of System.Reflection.Emit and MSIL.
using System;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Windows.Forms;
using System.Drawing.Design;

namespace XmlBindingManager
{
	/// <summary>
	/// Provides the binding between a control property and a xml property
	/// </summary>
	[TypeConverter(typeof(XmlBindingTypeConverter))]
	public class XmlBinding 
	{
		#region c'tors

		public XmlBinding()
		{}

		public XmlBinding(Control control)
		{
			_control = control;
		}

		public XmlBinding(string boundProperty, string xmlProperty) 
		{
			_controlProperty = boundProperty;
			_xmlProperty = xmlProperty;
		}

		#endregion

		#region Properties

		[Browsable(false)]
		public Control Control 
		{
			get { return _control; }
			set { _control = value; }
		}

		[Description("Property name of the bound property of this control")]
		public string BoundProperty
		{
			get { return _controlProperty; }
			set { _controlProperty = value; }
		}

		[Description("Property name of the xml wrapper object")]
		[Editor(typeof(XmlPropertyEditor), typeof(UITypeEditor))]
		public string XmlProperty
		{
			get { return _xmlProperty; }
			set { _xmlProperty = value; }
		}

		#endregion

		#region Fields

		private Control _control;
		private string _controlProperty;
		private string _xmlProperty;

		#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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here



Comments and Discussions