Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I don't understand why you don't just have expose a property like this in your ViewModel:</p> <pre><code>ObservableCollection&lt;object&gt; Items { get { var list = new ObservableCollection&lt;object&gt;(People); list.Add(Product); return list; } } </code></pre> <p>and then in your xaml you do this:</p> <pre><code>&lt;ListBox x:Name="TheListBox" ItemsSource={Binding Items}&gt; &lt;ListBox.Resources&gt; People and Product Data Templates &lt;/ListBox.Resources&gt; &lt;/ListBox&gt; ... &lt;ContentControl Content={Binding ElementName=TheListBox, Path=SelectedItem }&gt; &lt;ContentControl.Resources&gt; Data Templates for showing People and Product details &lt;/ContentControl.Resources&gt; &lt;/ContentControl&gt; </code></pre> <p><strong>UPDATE:</strong></p> <p>If you need to manipulate your model differently do the following:</p> <pre><code>ObservableCollection&lt;object&gt; _Items ObservableCollection&lt;object&gt; Items { get { if (_Items == null) { _Items = new ObservableCollection&lt;object&gt;(); _Items.CollectionChanged += EventHandler(Changed); } return _Items; } set { _Items = value; _Items.CollectionChanged += new CollectionChangedEventHandler(Changed); } } void Changed(object sender,CollectionChangedEventArgs e) { foreach(var item in e.NewValues) { if (item is Person) Persons.Add((Person)item); else if (item is Product) Products.Add((Product)item); } } </code></pre> <p>This is just an example. But if you modify the above to meet your needs, it might get you to your goal</p>
 

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