Note that there are some explanatory texts on larger screens.

plurals
  1. POHow are ListView's ItemCollections related?
    primarykey
    data
    text
    <p>If I create multiple <code>ListView</code>s with the same <code>ItemsSource</code> they become strangely linked. In the following example, the two <code>ListView</code>s display a common list of strings. The assertions show that the two <code>ItemCollection</code>s and <code>SortDescriptionCollection</code>s are distinct, but if I attempt to sort the <code>ListView</code>s differently, the second sort order is applied to both.</p> <p>The two <code>ItemCollection</code>s must be related in order for the <code>Selector.IsSynchronizedWithCurrentItem</code> property to have any effect, but I would like to be able to break this association so that I can do things like I've tried in this example. Does anyone know how these collections are related, and how I can sever this relationship?</p> <p>XAML:</p> <pre><code>&lt;Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:llv="clr-namespace:LinkedListViews" x:Class="LinkedListViews.Window1" x:Name="Window" Title="Window1" Width="640" Height="480"&gt; &lt;Grid x:Name="LayoutRoot"&gt; &lt;ListView x:Name="ListView1" ItemsSource="{Binding ElementName=Window, Path=Data}" Margin="75,8,0,8" Width="237" HorizontalAlignment="Left"/&gt; &lt;ListView x:Name="ListView2" ItemsSource="{Binding ElementName=Window, Path=Data}" HorizontalAlignment="Right" Margin="0,8,73,8" Width="243"/&gt; &lt;/Grid&gt; &lt;/Window&gt; </code></pre> <p>Code behind:</p> <pre><code>using System; using System.IO; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Navigation; using System.ComponentModel; using System.Collections.Generic; namespace LinkedListViews { public partial class Window1 { private List&lt;string&gt; _Data = new List&lt;string&gt; { "Alpha", "Beta", "Gamma" }; public List&lt;string&gt; Data { get { return _Data; } } public Window1() { this.InitializeComponent(); // Insert code required on object creation below this point. System.Diagnostics.Debug.Assert(ListView1.Items != ListView2.Items); System.Diagnostics.Debug.Assert(ListView1.Items.SortDescriptions != ListView2.Items.SortDescriptions); this.ListView1.Items.SortDescriptions.Add(new SortDescription(null, ListSortDirection.Ascending)); this.ListView2.Items.SortDescriptions.Clear(); this.ListView2.Items.SortDescriptions.Add(new SortDescription(null, ListSortDirection.Descending)); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
 

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