when clearing an observablecollection, there equipment e.olditems
i have something here unequivocally throwing me off guard.
i have an observablecollection t filled items. i also have an eventuality handler trustworthy collectionchanged event.
when clear collection causes an collectionchanged eventuality e.action set notifycollectionchangedaction.reset. ok, that's normal. nonetheless uncanny conjunction e.olditems e.newitems anything it. i design e.olditems filled equipment private collection.
has anyone else seen this? so, have gotten around it?
some background: i am controlling collectionchanged eventuality insert detach another eventuality so i don't any equipment e.olditems ... i won't means detach event.
clarification:
i know support doesn't outright state act way. nonetheless each action, notifying me done. so, audacity tell me ... box clear/reset well.
below illustration formula wish imitate yourself. initial off xaml:
<window
x:class="observablecollection.window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
title="window1"
height="300"
width="300"
>
<stackpanel>
<button x:name="addbutton" content="add" width="100" height="25" margin="10" click="addbutton_click"/>
<button x:name="movebutton" content="move" width="100" height="25" margin="10" click="movebutton_click"/>
<button x:name="removebutton" content="remove" width="100" height="25" margin="10" click="removebutton_click"/>
<button x:name="replacebutton" content="replace" width="100" height="25" margin="10" click="replacebutton_click"/>
<button x:name="resetbutton" content="reset" width="100" height="25" margin="10" click="resetbutton_click"/>
</stackpanel>
</window>
next, formula behind:
using system;
using system.collections.generic;
using system.linq;
using system.text;
using system.windows;
using system.windows.controls;
using system.windows.data;
using system.windows.documents;
using system.windows.input;
using system.windows.media;
using system.windows.media.imaging;
using system.windows.navigation;
using system.windows.shapes;
using system.collections.objectmodel;
namespace observablecollection
{
/// <summary>
/// communication explanation window1.xaml
/// </summary>
open biased category window1 : window
{
open window1()
{
initializecomponent();
_integerobservablecollection.collectionchanged += new system.collections.specialized.notifycollectionchangedeventhandler(_integerobservablecollection_collectionchanged);
}
private vacant _integerobservablecollection_collectionchanged(object sender, system.collections.specialized.notifycollectionchangedeventargs e)
{
switch (e.action)
{
box system.collections.specialized.notifycollectionchangedaction.add:
break;
box system.collections.specialized.notifycollectionchangedaction.move:
break;
box system.collections.specialized.notifycollectionchangedaction.remove:
break;
box system.collections.specialized.notifycollectionchangedaction.replace:
break;
box system.collections.specialized.notifycollectionchangedaction.reset:
break;
default:
break;
}
}
private vacant addbutton_click(object sender, routedeventargs e)
{
_integerobservablecollection.add(25);
}
private vacant movebutton_click(object sender, routedeventargs e)
{
_integerobservablecollection.move(0, 19);
}
private vacant removebutton_click(object sender, routedeventargs e)
{
_integerobservablecollection.removeat(0);
}
private vacant replacebutton_click(object sender, routedeventargs e)
{
_integerobservablecollection[0] = 50;
}
private vacant resetbutton_click(object sender, routedeventargs e)
{
_integerobservablecollection.clear();
}
private observablecollection<int> _integerobservablecollection = new observablecollection<int> { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 };
}
}
Comments
Post a Comment