Thursday, August 16, 2012

Custom DataGrid.RowGroupHeader with complicated binding

Custom DataGrid.RowGroupHeader with complicated binding

I'm trying to customize the binding of the text in the RowGroupHeader of my datagrid. I'm my style I've bound straight to the datasource of the rowgroupheader (I think its a MS.Internal.CollectionViewGroupInternal type)

<TextBlock Margin="4,0,0,0" Text="{Binding Converter={StaticResource TestConverter}}" /> 

And then in my converter I've done this:

public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)         {             CollectionViewGroup t = (CollectionViewGroup)value;              if (t.ItemCount == 0)                 return null;              if (t.IsBottomLevel)             {                 return ((MyCollectionObjectType)(t.Items[0])).RowDescription;             }             else             {                 CollectionViewGroup t2 = (CollectionViewGroup)t.Items[0];                 return ((MyCollectionObjectType)t2.Items[0]).TableName;             }         } 

My issue is I end up getting everything showing nicely and then something is causing the binding to be called again with t.Items == 0, and it clears all my text (as I am returning null). My desired behavior is that if there are no items in the group, then return whatever the last value for the Text was.

The only two solutions I can come up with involve passing either the old text value or the actual TextBlock control to the converter. I can't figure out how to do either.

'Cancelling' the binding would work as well, if that is even possible (I've tried returning null or throwing an error and neither and no luck).

Answers & Comments...




No comments:

Post a Comment

Send us your comment related to the topic mentioned on the blog