How to data bind nested ListView ItemTemplates in Metro/WinRT?

Viewed 8833

In my ViewModel I have a collection of objects which each contain another collection. I am trying to display this in my View by using nested ListView ItemTemplates. Here is a simplification of my ViewModel code:

public ViewModelObject
{
    public ObservableCollection<OuterObject> OuterCollection { get; }
}

public OuterObject
{
    public string OuterTitle;
    public ObservableCollection<InnerObject> InnerCollection { get; }
}

public InnerObject
{
    public string InnerTitle;
}

And here is a simplification of how I'm trying to use this ViewModel in my XAML:

<ListView ItemsSource="{Binding OuterCollection}">
    <ListView.ItemTemplate>
        <DataTemplate>
            <StackPanel>
                <TextBlock Text="{Binding OuterTitle}"/>
                <ListView ItemsSource="{Binding InnerCollection}">
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding InnerTitle}"/>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>
            </StackPanel>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

If I remove the inner ListView, the outer ListView binding works perfectly fine. I just can't figure out how to properly bind the inner collection object to the inner ListView. I've tried doing the inner binding with {Binding OuterCollection.InnerCollection}, {Binding DataContext.InnerCollection}, and {Binding RelativeSource={RelativeSource TemplatedParent}, Path=InnerCollection}, but all of these cause it to crash. What is the proper way to achieve this nested binding?

EDIT: I should add that this is for an application being ported from Windows Phone 7, and it is an attempt to find a replacement for LongListSelector, which is not available in WinRT.

1 Answers
Related