• subscribe
October 30, 2008 12:00 AM

Efficient Data Binding with Windows Presentation Foundation and Visual Studio 2008

Automate the development process with a free new tool
SQL Server Pro
InstantDoc ID #100362
Downloads
100362.zip

After the call to GetControlDefinitions, the Load- ControlsToGrid method has a generic list of all the XAML controls. The remaining code in this method walks through the items in the generic list and adds the valid ones to the DataGridView. The method determines which controls can be bound by calling the IsValidBindingType function, which returns True if the control’s type matches one in the Select statement of the IsValidBindingType function.

Now you have enough code to load all of the controls that can be bound that are in a XAML form into a DataGridView. You need to feed in the source of the data you want to display to allow the user to match up the data fields with the controls on the form. The data field to match to a control is selected by the user from the Data Source Type ComboBox. The list of items a user can choose in this combo box is set as either a DataTable (by allowing the user to select a SQL Server table) or Class (property class).

If users choose Class from the Data Source Type ComboBox, they will be prompted to select a property class. Then the tool will read the property class by calling the ProcessClassFileAnd- LoadProperties method in the DataBindingClass. This method simply reads the class file and finds all the property definitions and places them in a generic list.

If users select DataTable from the Data Source Type ComboBox, the tool displays other fields that point to the SQL Server table to bind to, as Figure 3 shows. Now you can enter a connection string and click the check mark to retrieve the list of tables from the database. Then you have just select a table from Tables ComboBox, and you can wire up the form.

The tool uses the MetaDataSQLServerSimple class to extract metadata from SQL Server, so it's easy to pull back information like table names and table fields.

Get Creative with the Tool

I hope you’ll enjoy working with this automation tool, but it’s just a starting point. For instance, you could add stored procedures to the tables so a developer could select a stored procedures output. Currently, the tool generates only Visual Basic .NET code, but you could modify it to generate C# code. Or, instead of wiring up WPF, try wiring up Silverlight 2.0. You could add many other features. If you want to change the tool, have at it.

Statement of Ownership
Statement of Ownership, Management, and Circulation for SQL Server Magazine as required by 39 U.S.C. 3685; SQL Server Magazine, publication no. 1522-2187, filed October 1, 2008, to publish twelve monthly issues each year for an annual subscription price of $49.95. The mailing address of the office of publication, the headquarters of general business of Jeff Lewis, Group Publisher, Michele Crockett, Associate Publisher, Karen Forster, Editorial and Strategy Director, is 221 E. 29th St., Loveland, CO 80538. The owner is Penton Media Inc, 249 W. 17th St., 4th Floor, New York, NY 10011-5390. Penton Business Media Holdings, Inc., of 249 W. 17th St., 4th Floor, New York, NY 10011-5390 owns 100% stock in Penton Media, Inc. The average number of copies of each issue published during the twelve months preceding the filing date include: total number of copies (28,497); paid mail subscriptions (17,984); sales through dealers and carriers, street vendors, counter sales, and other non-USPS paid distribution (4,537); other USPS paid distribution (286); total paid circulation (22,807); free or nominal rate distribution by mail (1,957); free or nominal rate distribution outside the mail (1,530); total distribution (26,294); copies not distributed (2,203); for a total of (28,497) copies. The actual number of copies of single issues published nearest to the filing date include: total number of copies (29,366); paid mail subscriptions (16,409); sales through dealers and carriers, street vendors, counter sales, and other non-USPS paid distribution (4,128); other USPS paid distribution (383); total paid circulation (20,920); free or nominal rate distribution by mail (1,682); free or nominal rate distribution outside the mail (4,237); total distribution (26,839); copies not distributed (2,527); for a total of (29,366) copies.

I certify that the statements made by me above are correct and complete: —Michele Crockett, Associate Publisher

 



ARTICLE TOOLS

Comments
    There are no comments to display. Be the first one!
You must log on before posting a comment.

Are you a new visitor? Register Here