closing a node in a stackpanel
I have this project where I have a stackpanel with control elements, each control element has a property called MyNextNode which contains the next object in the chain. My problem occurs when I try to close one of the nodes in this chain. I get the error "Value does not fall within the expected range."
here is my code.
WFElement orignextnode = this.NextNode
this.PrevNode.NextNode = orignexnode
Next node is a dependency property that triggers this code when changed
protected static void OnNextNodeValueChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
{
WFElement wfe = o as WFElement;
WFElement newElem = null;
if (e.NewValue != null)
{
newElem = e.NewValue as WFElement;
wfe.MyNextNode.Content = newElem;
}
else
{
wfe.MyNextNode.Content = null;
}
if (e.OldValue != null && newElem != null)
{
newElem.NextNode = e.OldValue as WFElement;
}
}
I get that error on {wfe.MyNextNode.Content = newElem;}. If I change the second line to
this.PrevNode.NextNode = null;
it works however, if there are elements after the deleted element, they get deleted as well.
Thank you in advance