views:

287

answers:

1

I have a WPf ListView that i am replacing the View with GridView to give me columns etc.

I want to apply a Cell Content Template to the Column and do a binding from the Cell template to the GridViewColumn (I have subclassed the column and it has some extra properties)

any ideas?

A: 

Well that should be pretty easy:

<GridViewColumn x:Name="myColumn" Header="My Header">
<GridViewColumn.CellTemplate>
    <DataTemplate>
        <TextBlock Text="{Binding ElementName=myColumn, Path=Header}"
                   TextAlignment="Right" Width="auto"/>
    </DataTemplate>
</GridViewColumn.CellTemplate>

Just name your column and in the binding supply the name as ElementName and you will be able to bind to the properties of your column.

That should do the trick.

Milan Nankov
thank you, however I am creating the columns dynamically. turns out that the column headers are not ancestors of the cells in the columns so i dont think i can crawl the visual tree to find them. I have given this my best shot and have moved over to the wpf toolkit datagrid, which gives me a lot less headaches than trying to write my own.
Aran Mulholland