I use DataTemplateSelector for ListView column headers template selection. ListView itself is in DataTemplate and ends up in a few tabs. So, in practice, I have same DataTemplate (so ListView too) shared between more TabItems. This means that if I select tab {A} and set XDataTemplate on ListView column {AColumn}, if I switch the tab, lets say to tab {B}, on {B}'s ListView (that is always the same one) column {AColumn} we will see the same XDataTemplate, because we share same UI data. So I created data layer where I hold relational information about {Tab} <-> {ListView:Column} <-> {HeaderContent}, which actually reads DatatemplateSelector in order correctly update UI on user screen. What I need is to notify to DataTemplateSelector to update current view in the moment that I need. How can I achieve that goal? Thank you.
A:
Ok, I come out with solution also for this problem. It wasn't difficult, as it seemed to me before. Actually, as the template is applied to ListView column's Header, it's enough to vary the header's value in order to generate WPF's internal event that will execute SelectTemplate on DataTemplateSelector automatically. Here is sample code:
if (MyListView != null)
{
foreach (GridViewColumn col in (MyListView.View as GridView).Columns)
{
string header = col.Header.ToString();
col.ClearValue(GridViewColumn.HeaderProperty);
col.SetValue(GridViewColumn.HeaderProperty, header);
}
}
That is. Hope this will help someone in the future. Thank you all.
Tigran
2009-08-23 11:27:35