Traveling the Avalon road, first experiences with databinding…
For some unknown reason, Microsoft has to decided not to release a DataGrid like control with the WPF libraries. This is quite a barrier to getting up and running fast when building a data intensive business application. This was some correspondence that I received from MS on the issue in the microsoft.public.windows.developer.winfx.avalon newsgroup:
Thanks for your feedback, we’ve always thought of data grid as an important control but it’s nice to hear you confirm that thinking. While Microsoft doesn’t plan to write a data grid in the WPF V1 timeframe, we’re working with component vendors to ensure a vibrant set a third party components for WPF, and we expect that data grids will be among the most popular offerings. Infragistics for example announced its DataPresenter for WPF at the PDC (I understand they’re putting together some form of CTP program for their components, might want to contact them if you’re interested). We’ll also keep your feedback in mind when we begin planning future versions of WPF.
Well, gee, thanks. So I went and grabbed the nifty beta version of the Infragistics DataPresenter control. It looks promising in the PDC videos, but currently fails to compile:
Jason,
The WPF controls we have made publicly available are designed to work only against the PDC build of WinFX, and therefore you will see errors if you attempt to use them against the November CTP. We will be releasing updated versions of the controls sometime in the future.
Ok, great. Except that everyone just jumped to the December CTP! Let’s hope for some backward compatibility. While not wanting to wait around, I’m attempting to see what I can get by designing my own custom grid control in XAML by slapping together some layout grids, buttons and text boxes. Forgetting about rendering performance for now, I’m just trying to databind each cell of the grid to a particular cell in the DataTable that I’m binding to using the Binding object in C#:
TextBlock tb = new TextBlock();
Binding b = new Binding("Table.Rows[" + rowCount + "][" + columnCount + "]");
b.Mode = BindingMode.TwoWay;
b.Source = this.DataView;
tb.SetBinding(TextBlock.TextProperty, b);
This assumes that my custom DataGrid control has a Dependency Property “DataView”, therefore I’m binding to the DataView’s Table.Rows collection, using the provided indexer to zero in on the correct column and row. This will unfortunately be unable to ever update the data in the table based on changes in the DataView.
Again from microsoft.public.windows.developer.winfx.avalon:
DataTable doesn’t generate property changes- you change the contents, but nothing notifies the UI that the stuff changed. To get this, you need to make a wrapper for the DataTable that generates the necessary events (INotifyCollectionChanged), or exposes the data as an ObservableCollection.
The ObservableCollection is a super lame conversion, and Avalon has completely ignored the entire System.Data framework. I don’t know what to say, but the two don’t communicate. Sorry.
While following those instructions to make DataView implement INotifyCollectionChanged does work, it mucks up my code more than I like. And doesn’t it defeat the purpose of using databinding if you need to manually fire all changes anyway?
I’ll leave you with with this quote from the O’Reilly Programming Windows Presentation Foundation book:
As of the current build, WPF has no direct support for binding to relational databases, and the indirect support is not in such great shape either
Well, it’s not like anyone would ever want to do something crazy that like anyway, would they?



December 25th, 2005 at 10:55 pm
INotifyCollectionChanged is _way_ too complicated an event. INotifyPropertyChanged isnt implemented anywhere.
DLinq has yet another XXXChanged protocol.
I imagine we can expect all this to be rationalized over the next few releases. Or not, as the case may be.
January 19th, 2006 at 1:30 pm
Jason,
Something you should consider is using the Windows Forms DataGridView control that shipped with 2.0 of the .Net Framework. You can use this control in a WPF app via Windows Forms – WPF interop. You can check out my blog for more information on the subject.