Saturday, February 28, 2015

DataTemplateSelector not being called

I have a DataTemplateSelector defined as follows:

Public Class FigureBindingTemplateSelector : Inherits DataTemplateSelector
Public Property TextFigureBindingTemplate() As DataTemplate
Public Property PathFigureBindingTemplate() As DataTemplate
Protected Overrides Function SelectTemplateCore(item As Object) As DataTemplate
Dim figure As Object = item.GetType().GetRuntimeProperty("Figure").GetValue(item)
If TypeOf (figure) Is TextFigureBinding Then : Return Me.TextFigureBindingTemplate
ElseIf TypeOf (figure) Is PathFigureBinding Then : Return Me.PathFigureBindingTemplate
Else : Return MyBase.SelectTemplateCore(item)
End If
End Function
End Class

The DataTemplateSelector is included in my Page's Resources as follows:

<ctrl:FigureBindingTemplateSelector x:Key="FBTSelector" TextFigureBindingTemplate="{StaticResource TextFigureBindingTemplate}" PathFigureBindingTemplate="{StaticResource PathFigureBindingTemplate}"/>

And I have an ItemsControl that uses it as follows:

<ItemsControl x:Name="itmCurrFigures" ItemTemplateSelector="{StaticResource FBTSelector}">
<ItemsControl.ItemsPanel><ItemsPanelTemplate><StackPanel/></ItemsPanelTemplate></ItemsControl.ItemsPanel>
</ItemsControl>

However, when I bind the ItemsControl by setting the ItemsSource property, the DataTemplateSelector is never called. I have tried putting a Breakpoint in the DataTemplateSelector, but it is never approached. I know that the binding happens, because my app does display the data I am binding (unformatted, of course, since it is not getting a template). Why is my DataTemplateSelector being ignored? Any help would be appreciated.


Nathan Sokalski njsokalski@hotmail.com http://ift.tt/1itfYLg


No comments:

Post a Comment