I'm using WPF with .NET 3.0.
I have a relatively simple DataTemplate defined as the CellTemplate for a GridView. I expect the DataTemplate's VisualTree property to contain a FrameworkElementFactory, but the property is null when I try to access it from the GridViewColumnHeader.Click event. Why is the VisualTree null? I need to access it. Here is the ListView definition:
<ListView ItemsSource="{Binding Stuff}" GridViewColumnHeader.Click="Header_Click">
<ListView.View>
<GridView>
<GridViewColumn Width="28">
<GridViewColumn.CellTemplate>
<DataTemplate>
<Image Name="statusImage" Width="16" Height="16" Source="../Images/media_play_green_16x16.png"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
And here is the event handler:
private void Header_Click(object sender, RoutedEventArgs e)
{
GridViewColumnHeader gvch = e.OriginalSource as GridViewColumnHeader;
// error! VisualTree is null!
//gvch.Column.CellTemplate.VisualTree.GetType();
}