tags:

views:

46

answers:

0

I have a GridView control and I am adding GridViewColumns. I was using DisplayMemberBinding property of GridViewColumn but now I want to use the CellTemplate. I am binding to a dictionary.

The following code worked with DisplayMemberBinding:

var column = new GridViewColumn
                                 {
                                     Header = current.Key,
                                    DisplayMemberBinding = new Binding("[" + current.Key + ]")

                                 };

Now, I need to do the same with CellTemplate but for some reason I am not sure why it is not displaying the items.

var column = new GridViewColumn { Header = current.Key,

                             CellTemplate = (DataTemplate)FindResource("GridViewTextBlockDataTemplate"),
                         };

And here is the DataTemplate defined in Window.Resources:

 <DataTemplate x:Key="GridViewTextBlockDataTemplate" x:Name="GridViewTextBlockDataTemplate">
            <TextBlock Text="{Binding Path=[Key]}"></TextBlock>
        </DataTemplate>

Thanks, Azam