Browse Source

Moved Name to Control.

pull/464/head
Steven Kirk 11 years ago
parent
commit
663b1fe490
  1. 39
      src/Perspex.Controls/Control.cs
  2. 43
      src/Perspex.SceneGraph/Visual.cs

39
src/Perspex.Controls/Control.cs

@ -31,7 +31,7 @@ namespace Perspex.Controls
/// - Implements <see cref="IStyleable"/> to allow styling to work on the control.
/// - Implements <see cref="ILogical"/> to form part of a logical tree.
/// </remarks>
public class Control : InputElement, IControl, ISetLogicalParent
public class Control : InputElement, IControl, INamed, ISetLogicalParent
{
/// <summary>
/// Defines the <see cref="DataContext"/> property.
@ -48,6 +48,12 @@ namespace Perspex.Controls
public static readonly StyledProperty<ITemplate<IControl>> FocusAdornerProperty =
PerspexProperty.Register<Control, ITemplate<IControl>>(nameof(FocusAdorner));
/// <summary>
/// Defines the <see cref="Name"/> property.
/// </summary>
public static readonly DirectProperty<Control, string> NameProperty =
PerspexProperty.RegisterDirect<Control, string>(nameof(Name), o => o.Name, (o, v) => o.Name = v);
/// <summary>
/// Defines the <see cref="Parent"/> property.
/// </summary>
@ -78,6 +84,7 @@ namespace Perspex.Controls
public static readonly RoutedEvent<RequestBringIntoViewEventArgs> RequestBringIntoViewEvent =
RoutedEvent.Register<Control, RequestBringIntoViewEventArgs>("RequestBringIntoView", RoutingStrategies.Bubble);
private string _name;
private IControl _parent;
private readonly Classes _classes = new Classes();
private DataTemplates _dataTemplates;
@ -126,6 +133,36 @@ namespace Perspex.Controls
/// </remarks>
public event EventHandler DataContextChanged;
/// <summary>
/// Gets or sets the name of the control.
/// </summary>
/// <remarks>
/// An element's name is used to uniquely identify a control within the control's name
/// scope. Once the element is added to a logical tree, its name cannot be changed.
/// </remarks>
public string Name
{
get
{
return _name;
}
set
{
if (value.Trim() == string.Empty)
{
throw new InvalidOperationException("Cannot set Name to empty string.");
}
if (VisualRoot != null)
{
throw new InvalidOperationException("Cannot set Name : control already added to tree.");
}
_name = value;
}
}
/// <summary>
/// Gets or sets the control's classes.
/// </summary>

43
src/Perspex.SceneGraph/Visual.cs

@ -27,7 +27,7 @@ namespace Perspex
/// To traverse the scene graph (aka Visual Tree), use the extension methods defined
/// in <see cref="VisualExtensions"/>.
/// </remarks>
public class Visual : Animatable, IVisual, INamed
public class Visual : Animatable, IVisual
{
/// <summary>
/// Defines the <see cref="Bounds"/> property.
@ -47,12 +47,6 @@ namespace Perspex
public static readonly StyledProperty<bool> IsVisibleProperty =
PerspexProperty.Register<Visual, bool>(nameof(IsVisible), true);
/// <summary>
/// Defines the <see cref="Name"/> property.
/// </summary>
public static readonly DirectProperty<Visual, string> NameProperty =
PerspexProperty.RegisterDirect<Visual, string>(nameof(Name), o => o.Name, (o, v) => o.Name = v);
/// <summary>
/// Defines the <see cref="Opacity"/> property.
/// </summary>
@ -83,11 +77,6 @@ namespace Perspex
public static readonly StyledProperty<int> ZIndexProperty =
PerspexProperty.Register<Visual, int>(nameof(ZIndex));
/// <summary>
/// The name of the visual, if any.
/// </summary>
private string _name;
/// <summary>
/// The visual's bounds relative to its parent.
/// </summary>
@ -176,36 +165,6 @@ namespace Perspex
set { SetValue(IsVisibleProperty, value); }
}
/// <summary>
/// Gets or sets the name of the visual.
/// </summary>
/// <remarks>
/// An element's name is used to uniquely identify a control within the control's name
/// scope. Once the element is added to a visual tree, its name cannot be changed.
/// </remarks>
public string Name
{
get
{
return _name;
}
set
{
if (value.Trim() == string.Empty)
{
throw new InvalidOperationException("Cannot set Name to empty string.");
}
if (VisualRoot != null)
{
throw new InvalidOperationException("Cannot set Name : control already added to tree.");
}
_name = value;
}
}
/// <summary>
/// Gets the opacity of the scene graph node.
/// </summary>

Loading…
Cancel
Save