views:

1791

answers:

1

I am trying to set the DataTemplate of my ListView.GridView's CellTemplate dynamically at runtime. The problem is when I do this, nothing happens. I checked the CellTemplate and it's not null but its VisualTree property is null. Any suggestions?

GridViewColumn gvc = new GridViewColumn
    {
        Header = col.Label ?? col.Name,
        DisplayMemberBinding = binding                        
    };

DataTemplate cellTemplate = FindDataTemplate(listView, col.CellTemplate);
if (cellTemplate != null)
    gvc.CellTemplate = cellTemplate;

gridView.Columns.Add(gvc);
+2  A: 

Apparently, when you set the DisplayMemberBinding, the CellTemplate is ignored. So when using CellTemplate, do not set DisplayMemberBinding.

http://krishnabhargav.blogspot.com/2009/06/gridviewcolumn-celltemplate-does-not.html

Tawani