Browse Source

Allow OnDetachedFromLogicalTree to be fired > once.

As it can happen now that TemplatedControl is correctly detaching
template children.
pull/467/head
Steven Kirk 11 years ago
parent
commit
886b837291
  1. 38
      src/Perspex.Controls/Control.cs

38
src/Perspex.Controls/Control.cs

@ -515,29 +515,29 @@ namespace Perspex.Controls
/// </remarks>
protected virtual void OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs e)
{
if (!_isAttachedToLogicalTree)
{
throw new Exception("Logic error: Control is not attached to logical tree");
}
if (Name != null)
if (_isAttachedToLogicalTree)
{
_nameScope?.Unregister(Name);
}
if (Name != null)
{
_nameScope?.Unregister(Name);
}
_isAttachedToLogicalTree = false;
_styleDetach.OnNext(Unit.Default);
this.TemplatedParent = null;
DetachedFromLogicalTree?.Invoke(this, e);
_isAttachedToLogicalTree = false;
_styleDetach.OnNext(Unit.Default);
this.TemplatedParent = null;
DetachedFromLogicalTree?.Invoke(this, e);
foreach (var child in LogicalChildren.OfType<Control>())
{
child.OnDetachedFromLogicalTree(e);
}
foreach (var child in LogicalChildren.OfType<Control>())
{
child.OnDetachedFromLogicalTree(e);
}
if (((InccDebug)_classes).GetCollectionChangedSubscribers()?.Length > 0)
{
System.Diagnostics.Debugger.Break();
if (((InccDebug)_classes).GetCollectionChangedSubscribers()?.Length > 0)
{
// TODO: This should be output using a standard logging mechanism.
System.Diagnostics.Debug.WriteLine(
$"{this.GetType().Name} detached from logical tree but still has class listeners");
}
}
}

Loading…
Cancel
Save