Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to data bind nested ListView ItemTemplates in Metro/WinRT?
    primarykey
    data
    text
    <p>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:</p> <pre><code>public ViewModelObject { public ObservableCollection&lt;OuterObject&gt; OuterCollection { get; } } public OuterObject { public string OuterTitle; public ObservableCollection&lt;InnerObject&gt; InnerCollection { get; } } public InnerObject { public string InnerTitle; } </code></pre> <p>And here is a simplification of how I'm trying to use this ViewModel in my XAML:</p> <pre><code>&lt;ListView ItemsSource="{Binding OuterCollection}"&gt; &lt;ListView.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;StackPanel&gt; &lt;TextBlock Text="{Binding OuterTitle}"/&gt; &lt;ListView ItemsSource="{Binding InnerCollection}"&gt; &lt;ListView.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;TextBlock Text="{Binding InnerTitle}"/&gt; &lt;/DataTemplate&gt; &lt;/ListView.ItemTemplate&gt; &lt;/ListView&gt; &lt;/StackPanel&gt; &lt;/DataTemplate&gt; &lt;/ListView.ItemTemplate&gt; &lt;/ListView&gt; </code></pre> <p>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 <code>{Binding OuterCollection.InnerCollection}</code>, <code>{Binding DataContext.InnerCollection}</code>, and <code>{Binding RelativeSource={RelativeSource TemplatedParent}, Path=InnerCollection}</code>, but all of these cause it to crash. What is the proper way to achieve this nested binding?</p> <p><strong>EDIT:</strong> 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 <code>LongListSelector</code>, which is not available in WinRT.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload