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?

5
  • 1
    Have you looked into CompositeCollection? Commented Jun 9, 2014 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) Commented Jun 9, 2014 at 23:47
  • 1
    Does my example here help? stackoverflow.com/a/23772569/1783619 Commented Jun 9, 2014 at 23:58
  • possible duplicate of Add extra items when using ItemsSource Commented Jun 10, 2014 at 4: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) Commented Jun 10, 2014 at 9:19

1 Answer 1

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>
Sign up to request clarification or add additional context in comments.

1 Comment

Yes, this is exactly the type of solution I was trying to avoid. It is a working solution though, so sorry for not accepting.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.