Browse Source

Moved Parent property to visual.

Visuals have parents too.
pull/4/head
grokys 12 years ago
parent
commit
65d701ffa9
  1. 14
      Perspex/Controls/ContentControl.cs
  2. 12
      Perspex/Controls/Control.cs
  3. 25
      Perspex/Visual.cs

14
Perspex/Controls/ContentControl.cs

@ -19,13 +19,17 @@ namespace Perspex.Controls
{ {
this.GetObservable(ContentProperty).Subscribe(x => this.GetObservable(ContentProperty).Subscribe(x =>
{ {
Visual visual = x as Visual; IVisual visual = x as IVisual;
Control control = x as Control; ILogical logical = x as ILogical;
if (control != null) if (visual != null)
{ {
((IVisual)control).VisualParent = this; visual.VisualParent = this;
control.SetValue(ParentPropertyRW, this); }
if (logical != null)
{
logical.LogicalParent = this;
} }
}); });
} }

12
Perspex/Controls/Control.cs

@ -34,9 +34,6 @@ namespace Perspex.Controls
public abstract class Control : Interactive, ILayoutable, IStyleable public abstract class Control : Interactive, ILayoutable, IStyleable
{ {
public static readonly ReadOnlyPerspexProperty<Control> ParentProperty =
new ReadOnlyPerspexProperty<Control>(ParentPropertyRW);
public static readonly PerspexProperty<Brush> BackgroundProperty = public static readonly PerspexProperty<Brush> BackgroundProperty =
PerspexProperty.Register<Control, Brush>("Background", inherits: true); PerspexProperty.Register<Control, Brush>("Background", inherits: true);
@ -67,9 +64,6 @@ namespace Perspex.Controls
public static readonly RoutedEvent<MouseEventArgs> MouseLeftButtonUpEvent = public static readonly RoutedEvent<MouseEventArgs> MouseLeftButtonUpEvent =
RoutedEvent.Register<Control, MouseEventArgs>("MouseLeftButtonUp", RoutingStrategy.Bubble); RoutedEvent.Register<Control, MouseEventArgs>("MouseLeftButtonUp", RoutingStrategy.Bubble);
internal static readonly PerspexProperty<Control> ParentPropertyRW =
PerspexProperty.Register<Control, Control>("Parent");
private Classes classes; private Classes classes;
private string id; private string id;
@ -219,12 +213,6 @@ namespace Perspex.Controls
set { this.SetValue(MarginProperty, value); } set { this.SetValue(MarginProperty, value); }
} }
public Control Parent
{
get { return this.GetValue(ParentPropertyRW); }
internal set { this.SetValue(ParentPropertyRW, value); }
}
public Styles Styles public Styles Styles
{ {
get get

25
Perspex/Visual.cs

@ -10,10 +10,17 @@ namespace Perspex
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics.Contracts; using System.Diagnostics.Contracts;
using System.Linq; using System.Linq;
using Perspex.Controls;
using Perspex.Media; using Perspex.Media;
public abstract class Visual : PerspexObject, IVisual, ILogical public abstract class Visual : PerspexObject, IVisual, ILogical
{ {
public static readonly ReadOnlyPerspexProperty<Control> ParentProperty =
new ReadOnlyPerspexProperty<Control>(ParentPropertyRW);
internal static readonly PerspexProperty<Control> ParentPropertyRW =
PerspexProperty.Register<Control, Control>("Parent");
private ILogical logicalParent; private ILogical logicalParent;
private IVisual visualParent; private IVisual visualParent;
@ -24,10 +31,24 @@ namespace Perspex
protected set; protected set;
} }
public Control Parent
{
get { return this.GetValue(ParentPropertyRW); }
protected set { this.SetValue(ParentPropertyRW, value); }
}
ILogical ILogical.LogicalParent ILogical ILogical.LogicalParent
{ {
get { return this.logicalParent; } get
set { this.logicalParent = value; } {
return this.logicalParent;
}
set
{
this.logicalParent = value;
this.Parent = value as Control;
}
} }
IEnumerable<ILogical> ILogical.LogicalChildren IEnumerable<ILogical> ILogical.LogicalChildren

Loading…
Cancel
Save