RowHeader and Databinding update problems

Jun 7, 2009 at 12:48 PM
Edited Jun 7, 2009 at 12:49 PM


I want to display a special RowHeader for each row in mit DataGrid.

For this I have made a RowVM (ViewModel) class which is just a standard List<double> with an extra Header field.

Simple and Looks like this:

        public class RowVM : List<double>
            public MyObject Header { get; set; }

I have created a Style for the rows that binds to that object

                <Style TargetType="dg:DataGridRowHeader">
                    <Setter Property="ContentTemplate">
                                <ContentControl Content="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type dg:DataGridRow}},

and than a general DataTemplate for MyObject is applied and basicly all works fine - well except for updates.

MyObject implements the INotifyPropertyChanged interface to propagate Property changes on which the DataTemplate of MyObject changes its looks. I use the DataTemplate for MyObject a lot in my program and it works fine - but not here.

Has anybody a clue why?

Greets and thank you


Jun 8, 2009 at 1:59 AM

This looks similar to a problem I had.  Your Binding source looks for a DataGridRow.  Your path refers to DataContext.Header.  I don't think your DataGridRow is seeing the correct DataContext.  I'm willing to bet you pointed the DataContext of an element higher in your element tree to RowVM.  One possibility is that you set the DataContext of the DataGrid (rather than DataGridRow) to RowVM.  Another possibility is that you set the DataContext of a UserControl or Window that contains the DataGrid to RowVM.  Technically DataGridRow should inherit that DataContext.  However, I think there is a "bug" in the DataGrid that prevents this from happening.

If what I stated is correct, try this:

AncestorType={x:Type dg:DataGrid}

Another possibility is to try the following if the you set the Window's DataContext

AncestorType={x:Type dg:Window}

A third possibility is to try the following if your DataGrid is contained in a UserControl:

AncestorType={x:Type UserControl}