diff --git a/Perspex.Controls/Generators/ItemContainerGenerator.cs b/Perspex.Controls/Generators/ItemContainerGenerator.cs
index ad11d02d18..45551874a2 100644
--- a/Perspex.Controls/Generators/ItemContainerGenerator.cs
+++ b/Perspex.Controls/Generators/ItemContainerGenerator.cs
@@ -83,7 +83,6 @@ namespace Perspex.Controls.Generators
foreach (object item in items)
{
Control container = this.CreateContainerOverride(item);
- container.Parent = this.Owner;
container.TemplatedParent = null;
this.AddInternal(item, container);
result.Add(container);
diff --git a/Perspex.Controls/IItemsPanel.cs b/Perspex.Controls/IItemsPanel.cs
new file mode 100644
index 0000000000..6d655b1ab3
--- /dev/null
+++ b/Perspex.Controls/IItemsPanel.cs
@@ -0,0 +1,26 @@
+// -----------------------------------------------------------------------
+//
+// Copyright 2014 MIT Licence. See licence.md for more information.
+//
+// -----------------------------------------------------------------------
+
+namespace Perspex.Controls
+{
+ ///
+ /// Interface used by to set logical ownership of the panel's
+ /// children.
+ ///
+ ///
+ /// needs to set the logical parent of each of its items to itself.
+ /// To do this, it uses this interface to instruct the panel that instead of setting the
+ /// logical parent for each child to the panel itself, it should set it to that of
+ /// .
+ ///
+ public interface IItemsPanel
+ {
+ ///
+ /// Gets or sets the logical parent that should be set on children of the panel.
+ ///
+ ILogical ChildLogicalParent { get; set; }
+ }
+}
diff --git a/Perspex.Controls/ItemsControl.cs b/Perspex.Controls/ItemsControl.cs
index 7767904df4..265314264a 100644
--- a/Perspex.Controls/ItemsControl.cs
+++ b/Perspex.Controls/ItemsControl.cs
@@ -69,13 +69,7 @@ namespace Perspex.Controls
{
get
{
- if (this.logicalChildren == null)
- {
- this.logicalChildren = new PerspexReadOnlyListView(
- new PerspexList(),
- x => (ILogical)x);
- }
-
+ this.ApplyTemplate();
return this.logicalChildren;
}
}
diff --git a/Perspex.Controls/Panel.cs b/Perspex.Controls/Panel.cs
index ae9bbf21e3..46014c1791 100644
--- a/Perspex.Controls/Panel.cs
+++ b/Perspex.Controls/Panel.cs
@@ -15,10 +15,17 @@ namespace Perspex.Controls
///
/// Base class for controls that can contain multiple children.
///
- public class Panel : Control, ILogical
+ public class Panel : Control, ILogical, IItemsPanel
{
private Controls children;
+ private ILogical childLogicalParent;
+
+ public Panel()
+ {
+ this.childLogicalParent = this;
+ }
+
public Controls Children
{
get
@@ -58,32 +65,30 @@ namespace Perspex.Controls
}
}
- public bool IsLogicalParent { get; set; } = true;
-
IReadOnlyPerspexList ILogical.LogicalChildren
{
get { return this.children; }
}
+ ILogical IItemsPanel.ChildLogicalParent
+ {
+ get { return this.childLogicalParent; }
+ set { this.childLogicalParent = value; }
+ }
+
private void ClearLogicalParent(IEnumerable controls)
{
- if (this.IsLogicalParent)
+ foreach (var control in controls)
{
- foreach (var control in controls)
- {
- control.Parent = null;
- }
+ control.Parent = null;
}
}
private void SetLogicalParent(IEnumerable controls)
{
- if (this.IsLogicalParent)
+ foreach (var control in controls)
{
- foreach (var control in controls)
- {
- control.Parent = this;
- }
+ control.Parent = this.childLogicalParent as Control;
}
}
diff --git a/Perspex.Controls/Perspex.Controls.csproj b/Perspex.Controls/Perspex.Controls.csproj
index 4ca024736f..ab79d17bd9 100644
--- a/Perspex.Controls/Perspex.Controls.csproj
+++ b/Perspex.Controls/Perspex.Controls.csproj
@@ -38,6 +38,7 @@
+
diff --git a/Perspex.Controls/Presenters/ItemsPresenter.cs b/Perspex.Controls/Presenters/ItemsPresenter.cs
index 0cdc4b709c..32e8adfbf1 100644
--- a/Perspex.Controls/Presenters/ItemsPresenter.cs
+++ b/Perspex.Controls/Presenters/ItemsPresenter.cs
@@ -65,7 +65,7 @@ namespace Perspex.Controls.Presenters
{
this.ClearVisualChildren();
this.panel = this.ItemsPanel.Build();
- this.panel.IsLogicalParent = false;
+ ((IItemsPanel)this.panel).ChildLogicalParent = this.TemplatedParent as ILogical;
this.AddVisualChild(this.panel);
this.createdPanel = true;
this.ItemsChanged(Tuple.Create(default(IEnumerable), this.Items));