Browse Source

Don't allow null logical or visual children.

And remove RedirectLogicalChildren which is no longer needed, or
desired.
pull/390/head
Steven Kirk 11 years ago
parent
commit
d9f043b45d
  1. 43
      src/Perspex.Controls/Control.cs
  2. 13
      src/Perspex.SceneGraph/Visual.cs

43
src/Perspex.Controls/Control.cs

@ -278,32 +278,14 @@ namespace Perspex.Controls
if (_logicalChildren == null)
{
var list = new PerspexList<ILogical>();
LogicalChildren = list;
list.ResetBehavior = ResetBehavior.Remove;
list.Validate = ValidateLogicalChild;
list.CollectionChanged += LogicalChildrenCollectionChanged;
_logicalChildren = list;
}
return _logicalChildren;
}
set
{
Contract.Requires<ArgumentNullException>(value != null);
if (_logicalChildren != value)
{
if (_logicalChildren != null)
{
_logicalChildren.CollectionChanged -= LogicalChildrenCollectionChanged;
}
}
if (value is PerspexList<ILogical>)
{
((PerspexList<ILogical>)value).ResetBehavior = ResetBehavior.Remove;
}
_logicalChildren = value;
_logicalChildren.CollectionChanged += LogicalChildrenCollectionChanged;
}
}
/// <summary>
@ -520,15 +502,6 @@ namespace Perspex.Controls
DataContextChanged?.Invoke(this, EventArgs.Empty);
}
/// <summary>
/// Makes the control use a different control's logical children as its own.
/// </summary>
/// <param name="collection">The logical children to use.</param>
protected void RedirectLogicalChildren(IPerspexList<ILogical> collection)
{
LogicalChildren = collection;
}
/// <summary>
/// Called when the <see cref="DataContext"/> property begins and ends being notified.
/// </summary>
@ -566,6 +539,14 @@ namespace Perspex.Controls
return null;
}
private static void ValidateLogicalChild(ILogical c)
{
if (c == null)
{
throw new ArgumentException("Cannot add null to LogicalChildren.");
}
}
private void LogicalChildrenCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
switch (e.Action)

13
src/Perspex.SceneGraph/Visual.cs

@ -125,6 +125,7 @@ namespace Perspex
var visualChildren = new PerspexList<IVisual>();
visualChildren.ResetBehavior = ResetBehavior.Remove;
visualChildren.Validate = ValidateLogicalChild;
visualChildren.CollectionChanged += VisualChildrenChanged;
VisualChildren = visualChildren;
}
@ -457,6 +458,18 @@ namespace Perspex
}
}
/// <summary>
/// Ensures a visual child is not null.
/// </summary>
/// <param name="c">The visual child.</param>
private static void ValidateLogicalChild(IVisual c)
{
if (c == null)
{
throw new ArgumentNullException("Cannot add null to VisualChildren.");
}
}
/// <summary>
/// Called when the <see cref="RenderTransform"/>'s <see cref="Transform.Changed"/> event
/// is fired.

Loading…
Cancel
Save