LongListSelector ListFooterTemplate {Binding} Resolves to NULL

It’s quite common to have a ‘More’ button at the end of long lists within a LongListSelector. The problem is the template inexplicably doesn’t cascade the DataContext, so you have no access to the collection to trigger a more command. Fortunately the workaround is simple, albeit you can’t use pre-defined DataTemplates.

<toolkit:LongListSelector x:Name="SimilarList" ItemTemplate="{StaticResource GeneralCatalogListItemTemplate}" SelectionChanged="SimilarList_SelectionChanged" DataContext="{StaticResource dummyCatalogTitlesList}" ItemsSource="{Binding}" IsFlatList="True">
    <toolkit:LongListSelector.ListFooterTemplate>
        <DataTemplate>
            <bindings:CommandButton Content="More..." Command="{StaticResource moreCommand}" DataContext="{Binding ElementName=SimilarList, Path=DataContext}" CommandParameter="{Binding}" />
        </DataTemplate>
    </toolkit:LongListSelector.ListFooterTemplate>
</toolkit:LongListSelector>

You need to give your list a name, then when setting the DataContext for your controls make sure to provide the ElementName as seen above.

I’m not sure why the other templates cascade correctly and this one doesn’t, but I’m hopeful it’ll be fixed in a future release of the toolkit. As an aside there is a fairly clean workaround if/when MS add the Freezable class to WP7.

2 comments

Thanks a lot. I’ve been banging my head against the wall for a few hours now.

Thanks, Dan. You really saved the day. The ListHeaderTemplate has the same problem with uncascaded dataContext, BTW.

Leave a Reply to Vladimir Cancel reply