I need to dynamically add/remove GridView columns, each displaying information from a different element stored in a KeyedCollection (indexed with tn 'int'). The basic technique works, but requires an index, as follows:
<GridViewColumn Header="bid">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Width="60" DataContext="{Binding Elements}" Text="{Binding [546].PropName}" TextAlignment="Center" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
However, at run-time I need to add more of these, with different integer keys, at which point I'm not sure how to create new DataTemplates, each with a different binding index.
Constructing a new DataTemplate using the XamlParser seems quite ugly...
Any help?