|
|
@ -3,6 +3,7 @@ |
|
|
|
|
|
|
|
|
using System; |
|
|
using System; |
|
|
using System.Collections.Generic; |
|
|
using System.Collections.Generic; |
|
|
|
|
|
using Avalonia.LogicalTree; |
|
|
|
|
|
|
|
|
namespace Avalonia.Controls |
|
|
namespace Avalonia.Controls |
|
|
{ |
|
|
{ |
|
|
@ -29,6 +30,32 @@ namespace Avalonia.Controls |
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
public event EventHandler<NameScopeEventArgs> Unregistered; |
|
|
public event EventHandler<NameScopeEventArgs> Unregistered; |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Finds the containing name scope for a visual.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="visual">The visual.</param>
|
|
|
|
|
|
/// <returns>The containing name scope.</returns>
|
|
|
|
|
|
public static INameScope FindNameScope(Visual visual) |
|
|
|
|
|
{ |
|
|
|
|
|
Contract.Requires<ArgumentNullException>(visual != null); |
|
|
|
|
|
|
|
|
|
|
|
INameScope result; |
|
|
|
|
|
|
|
|
|
|
|
while (visual != null) |
|
|
|
|
|
{ |
|
|
|
|
|
result = visual as INameScope ?? GetNameScope(visual); |
|
|
|
|
|
|
|
|
|
|
|
if (result != null) |
|
|
|
|
|
{ |
|
|
|
|
|
return result; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
visual = (visual as ILogical).LogicalParent as Visual; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Gets the value of the attached <see cref="NameScopeProperty"/> on a visual.
|
|
|
/// Gets the value of the attached <see cref="NameScopeProperty"/> on a visual.
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
@ -36,6 +63,8 @@ namespace Avalonia.Controls |
|
|
/// <returns>The value of the NameScope attached property.</returns>
|
|
|
/// <returns>The value of the NameScope attached property.</returns>
|
|
|
public static INameScope GetNameScope(Visual visual) |
|
|
public static INameScope GetNameScope(Visual visual) |
|
|
{ |
|
|
{ |
|
|
|
|
|
Contract.Requires<ArgumentNullException>(visual != null); |
|
|
|
|
|
|
|
|
return visual.GetValue(NameScopeProperty); |
|
|
return visual.GetValue(NameScopeProperty); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -46,6 +75,8 @@ namespace Avalonia.Controls |
|
|
/// <param name="value">The value to set.</param>
|
|
|
/// <param name="value">The value to set.</param>
|
|
|
public static void SetNameScope(Visual visual, INameScope value) |
|
|
public static void SetNameScope(Visual visual, INameScope value) |
|
|
{ |
|
|
{ |
|
|
|
|
|
Contract.Requires<ArgumentNullException>(visual != null); |
|
|
|
|
|
|
|
|
visual.SetValue(NameScopeProperty, value); |
|
|
visual.SetValue(NameScopeProperty, value); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|