views:

110

answers:

1

Hi,

I've just updated my app with the latest WPF toolkit and I've now got an issue with my styling.

When I bind some data with, for example, two columns to the grid, the header in the spare area at the right shows the name of the ViewModel.

So if I bind an IEnumerable with two columns the Grid Header looks like

Column1, Column1, [Namespace].MyViewModel

Before the Feb 2010 update it just used to have Column1, Column2 - the final space being blank.

I can kind of understand why, because the data grids data context is the ViewModel, whereas the Columns seem to have a different DataContext ... but I can't work out how I'm supposed to fix it.

I'm defining my header style as follows ...

....

<WpfToolkit:DataGridHeaderBorder
    <Border BorderBrush="Blue" BorderThickness="0,1,0,0">
        <TextBlock Text="{Binding}" Margin="4,0,4,0" />
    </Border>
</WpfToolkit:DataGridHeaderBorder>

....

Do I now need a separate style for the 'spare column' or something?

Can anyone assist please?

Cheers,

Andy

+1  A: 

In the textblock (<TextBlock Text="{Binding}" Margin="4,0,4,0" />) you are binding directly to the ViewModel, which is an object. As fallback, object.ToString() is used while Binding, which is the name of the ViewModel. You have to specify a path ie. <TextBlock Text="{Binding Text}" Margin="4,0,4,0" /> to bind to.

Femaref
But doing that would mean that the column headers that have a data context of an actual value would not work.
Andy Clarke
Just don't bind the text then?
Femaref
Sorry I probably havnt been clear, I don't want the binding to apply to the 'spare column' - only the other columns, i don't know whether its a different type or something? It used to be fine before the Feb 2010 update.
Andy Clarke
Could you provide more code please?
Femaref
Hi, thanks for your help - i've added some more info to the question.
Andy Clarke