<p>I've created a ListBox with 10-20 ExpanderView objects inside, where each ExpanderView object contains 1 - 10 items. After I click on the ExpanderView objects to make them expand, and scrolled the list up and down a few times, a ExpanderView objects throws an "Invalid Operation Exception" with a message "Invalid operation. The IsExpanded property cannot be modified when IsNonExpandable is set to true."</p>
<p>After I go through the stack trace of exception and source code of ExpanderView ( i.e. ExpanderView.cs ), I found the cause was the value of "IsNonExpandableProperty" changed from false to true. ( So the value of IsNonExpandableProperty of this ExpanderView object is true now)</p>
<p>According to the source code of ExpanderView.cs, when the new value is "true" and "IsExpand" is "true", it will set IsExpand to false. However, when IsExpanded property is set, it will check the value of IsNonExpandableProperty, and if it's true, the Invalid Operation Exception will be thrown. </p>
<p>In order words, if an ExpanderView object, which is expanded, the "IsNonExpandable" property is set to true, it will cause Invalid Operation Exception because when IsExpanded property to be changed, it requires the property of "IsNonExpandable" to be false.</p>
Comments: ** Comment from web user: wilsonson **
<p>After I go through the stack trace of exception and source code of ExpanderView ( i.e. ExpanderView.cs ), I found the cause was the value of "IsNonExpandableProperty" changed from false to true. ( So the value of IsNonExpandableProperty of this ExpanderView object is true now)</p>
<p>According to the source code of ExpanderView.cs, when the new value is "true" and "IsExpand" is "true", it will set IsExpand to false. However, when IsExpanded property is set, it will check the value of IsNonExpandableProperty, and if it's true, the Invalid Operation Exception will be thrown. </p>
<p>In order words, if an ExpanderView object, which is expanded, the "IsNonExpandable" property is set to true, it will cause Invalid Operation Exception because when IsExpanded property to be changed, it requires the property of "IsNonExpandable" to be false.</p>
Comments: ** Comment from web user: wilsonson **
I found the problem is caused by "VirtualizingStackPanel". If "VirtualizingStackPanel" is used in the listbox, it will recycle the ExpanderView" object and therefore causing the problem.