A couple of issues with DataGrid and binding

Oct 14, 2009 at 8:33 AM

I'm learning to use the WPF DataGrid with the MVVM pattern and I have stumbled over a couple of minor issues.

I generally don't use the auto-generation feature for columns.
First for localization and then because often I don't want to visualize every property.

So I defined my columns manually in XAML and then the most natural thing to do seemed to bind the single headers to properties on the ViewModel.

Alas, this doesn't work.
I have to let the View pull the values from the ViewModel in the code-behind and update the Header contents programmatically.

I always bind the DataGrid's ItemSource property to another property on the ViewModel, usually a List.
In certain cases I don't want to use the DataGrid's built-in capabilities for adding/removing/editing rows.

So after having modified the list on the ViewModel I have it do something like InvokePropertyChanged("MyList");
However this doesn't work, I would have expected the DataGrid to pick-up the changes but this isn't the case.
In order to compensate for this I call something like grid.Items.Refresh() on the View.

For both cases I'd like to ask if this the intended behaviour and if you see something fundamentally wrong with my approach.
So far I'm having quite a good time with WPF and MVVM but since the DataGrid is a fundamental component of almost any LOB application these two quirks somewhat break consistency with how MVVM is usually implemented in WPF apps.