Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you enable CLR Exceptons to break when thrown (under Debug|Exceptions) you'll see this stack trace:</p> <pre><code>mscorlib.dll!System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument argument, System.ExceptionResource resource) + 0x10 bytes mscorlib.dll!System.ThrowHelper.ThrowArgumentOutOfRangeException() + 0x9 bytes mscorlib.dll!System.Collections.Generic.List&lt;object&gt;.this[int].get(int index) + 0xe bytes mscorlib.dll!System.Collections.ObjectModel.Collection&lt;object&gt;.System.Collections.IList.get_Item(int index) + 0x7 bytes System.Windows.dll!System.Windows.Controls.ItemCollection.GetItemImpl(int index) + 0x17 bytes System.Windows.dll!System.Windows.Controls.ItemCollection.GetItemImplSkipMethodPack(int index) + 0x2 bytes System.Windows.dll!System.Windows.PresentationFrameworkCollection&lt;object&gt;.this[int].get(int index) + 0x2 bytes System.Windows.dll!System.Windows.Controls.VirtualizingStackPanel.CleanupContainers(System.Windows.Controls.ItemsControl itemsControl) + 0xa3 bytes System.Windows.dll!System.Windows.Controls.VirtualizingStackPanel.MeasureOverride(System.Windows.Size constraint) + 0x56a bytes System.Windows.dll!System.Windows.FrameworkElement.MeasureOverride(System.IntPtr nativeTarget, float inWidth, float inHeight, out float outWidth, out float outHeight) + 0x45 bytes [External Code] </code></pre> <p>For some reason the virtualizing stack panel is trying to clean up the element at index -1 (you can see this value for index in the stack frame).</p> <p>The type of the ObservableCollection's contents makes no difference. You get the same error with strings ... and it happens with just two elements.</p> <p>To me it looks like a <a href="https://stackoverflow.com/questions/1659692/argumentoutofrangeexception-when-replacing-items-in-an-observablecollectiont">bug</a> in the VirtualizingStackPanel. You can work around it (if you don't need the virtualizing functionality) by setting the VirtualizationMode to Standard instead of Recycling on the ListBox:</p> <pre><code>&lt;ListBox VirtualizingStackPanel.VirtualizationMode="Standard" ... &lt;/ListBox&gt; </code></pre>
 

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