WinRT ItemTemplateSelector

Topics: Conventions
Apr 17, 2013 at 4:54 PM
Edited Apr 17, 2013 at 4:54 PM
I'm trying to use an ItemTemplateSelector on a ListView, however it's not working. I believe Caliburn is not finding an ItemTemplate and is assigning one by default.

Is this right?

Thanks

(P.S. It works if I use explicit Binding)
Apr 21, 2013 at 2:23 AM
Just to clarify you're using an x:Name on the ListView with an ItemTemplateSelector specified as well?
Apr 22, 2013 at 7:34 PM
Sorry. This is now working, but I've updated Caliburn since wednesday and this now is working. Don't know if that was the solution.
Apr 22, 2013 at 8:21 PM
I don't get it. I just got the same problem:

I have the following code:

View
(...)
    <Page.Resources>
        <selectors:NoteItemTemplateSelector x:Key="NoteItemTemplateSelector" 
                                            ReadTemplate="{StaticResource Notes600ConversationTemplate}"
                                            UnreadTemplate="{StaticResource Notes600ConversationTemplateUnread}"/>
    </Page.Resources>
(...)
<ListView x:Name="Conversations"
               ItemTemplateSelector="{StaticResource NoteItemTemplateSelector}">
       <ListView.ItemContainerStyle>
           <Style TargetType="ListViewItem">
               <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
           </Style>
       </ListView.ItemContainerStyle>
</ListView>
With this code, each item has a message: Cannot find view for ...blah blah.Converstation

If I add this code to the listView, it works ok:
ItemsSource="{Binding Conversations}"

Am I missing something?
Apr 22, 2013 at 9:01 PM
It looks like there's a logic flaw in the conventions, the ConventionManager currently isn't expecting the ItemTemplateSelector property to see whether it should use the default ItemTemplate. The ListView then uses the ItemTemplate that Caliburn Micro sets rather than the ItemTemplateSelector

By adding the ItemsSource binding yourself you short circuit the conventions.
Apr 22, 2013 at 9:13 PM