0

I have a ListView and I would like to display multiple collections of same type (contrary to all other topics I found about multiple binding), or even better - an unediable item, something like "default item", as first item in ListView and multiple concatenated collections of same type. For example for one collection and one item:

<ListView ItemsSource="{Binding People}">
        <ListView.ItemTemplate>
              <DataTemplate>
                 <WrapPanel>
                     <TextBlock Text="{Binding Name}" />
                </WrapPanel>
               </DataTemplate>
        </ListView.ItemTemplate>
        <ListViewItem ItemsSource="{Binding PatientZero}">
              <WrapPanel>
                 <TextBlock Text="{Binding Name}" />
              </WrapPanel>
        </ListViewItem>
</ListView>

and

public class Person
{
    public string Name { get; set; }
    public Person(){}
}

...and code

ObservableCollection<Person> _people =
       new ObservableCollection<Person>();

public ObservableCollection<Person> People
       { get { return _people; } }

Person PatientZero { get { return _patientZero ; } }
Person _patientZero = new Person { Name="Unknown"}

obviously, this wont work as it wont get past xaml parser (not mentioning some syntax, but this is an example). Ofcourse I could regulary concat all collections and check if edited item isnt the first one, but I am curious if this can be solved.
Any ideas who to achieve that?

Cœur
  • 37,241
  • 25
  • 195
  • 267
wondra
  • 3,271
  • 3
  • 29
  • 48
  • 1
    Have you looked into `CompositeCollection`? – BradleyDotNET Jun 09 '14 at 23:30
  • Can you provide code example for this situation? I am not sure how should I bind item and collection together... (with the official example it did not work) – wondra Jun 09 '14 at 23:47
  • 1
    Does my example here help? http://stackoverflow.com/a/23772569/1783619 – BradleyDotNET Jun 09 '14 at 23:58
  • possible duplicate of [Add extra items when using ItemsSource](http://stackoverflow.com/questions/23771679/add-extra-items-when-using-itemssource) – pushpraj Jun 10 '14 at 04:18
  • Thanks, it works fine and it is the solution i was looking for. Sadly, I did not found the thread before (mostly because the title doesnt match its contents). I would delete this question as it is duplicate but since the original is so badly formulated it might be better to keep it to avoid more duplicates. (you can add items to ItemsSource collection without any fancy stuff) – wondra Jun 10 '14 at 09:19

1 Answers1

1

Not sure if this is what you need. But your problem description can be clearer.

ObservableCollection<ObservableCollection<Person>> PeopleLists{get;set;}

Bind in XAML

<ListView ItemsSource="{Binding PeopleLists}">
    <ListView.ItemTemplate>
          <DataTemplate>
             <ListView ItemsSource={Binding}>
                 <ListView.ItemTemplate>
                     <DataTemplate>
                         <WrapPanel>
                            <TextBlock Text="{Binding Name}" />
                         </WrapPanel>
                     </DataTemplate>
                 </ListView.ItemTemplate>
             </ListView>
           </DataTemplate>
    </ListView.ItemTemplate>
</ListView>
nakiya
  • 14,063
  • 21
  • 79
  • 118
  • Yes, this is exactly the type of solution I was trying to avoid. It is a working solution though, so sorry for not accepting. – wondra Jun 10 '14 at 09:22