Do Databinding in C# codes

Databinding in C# codes offers the more flexible way to bind UI elments to the data source at run time. The following codes snippet gives the pattern to bind UI elements to XmlDataProvider.

{
Binding databinding = new Binding();
databinding.Mode = BindingMode.Default/OneWay/TwoWay…;
databinding.Source = SomeDataSourceObject;
databinding.XPath = SomeXPathString;
SomeUIElment.SetBinding(SomeClass.SomeDependencyProperty, databinding);
}

SomeClass can be the current calling UI element’s class, like the normal controls, also can be its holder’s class, like Grid and Panel.

Update:
If you need to databind your control with CLR data object, you should specify Path instead of XPath. The usual way is:
databinding.Path = new PathProperty(PathString);

Advertisements

~ by Martin on August 8, 2007.

One Response to “Do Databinding in C# codes”

  1. thanks a lot its really helpful, if any body want to implement basic data binding, I want to share a link where you can find tutorial for advanced data binding. its http://www.dapfor.com/en/net-suite/net-grid/tutorial/data-binding

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: