views:

26

answers:

1

I have a custom DataGrid mixed with DataGridTemplateColumns and a custom behavior derived from this answer http://stackoverflow.com/questions/3970363/silverlight-datagrid-highlight-an-entire-column-when-that-column-is-sorted. The problem I'm experiencing is that any DataGridTemplateColumn's cells are not picking up the 'highlight'. The cell template being used for the custom columns are of the structure shown below. Anyone have any ideas why the background highlight isn't being applied? I've been wracking my brain on this one for a while.

<DataTemplate>
    <Grid>
        <Border VerticalAlignment='Stretch' Margin='1' Background='Transparent'>
            <TextBlock VerticalAlignment='Center' Text='{Binding Path=Variable}' />
        </Border>
    </Grid>
</DataTemplate>
A: 

To solve this problem I ended up needing to create a string DependencyProperty called Background on the custom column class that inherits from DataGridTemplateColumn. Also, in the behavior, I had to check what type the column was.

Before, I would just case the column in the CollectionChanged event handler to a DataGridBoundColumn. Now I check to see if it is actually that type or if its a DataGridTemplateColumn. The DataGridTemplateColumn has a different way to check the binding path, the difference is shown below

DataGridBoundColumn: boundColumn.Binding.Path.Path DataGridTemplateColumn: boundColumn.SortMemberPath

The final tweak I had to make was to change the structure of the DataTemplate so that it now looks like below, basically setting the color a different way is all.

<DataTemplate>
    <Grid>
        <Border>
            <Border.Background>
                <SolidColorBrush Color='{0}' />
            </Border.Background>
            <TextBlock VerticalAlignment='Center' Text='{Binding Path=Variable}' />
        </Border>
    </Grid>
</DataTemplate>
GotDibbs