Browse Source

Allow any object implementing INamed to be registered in a Xaml namescope (#14757)

Added INamed as direct interface of StyledElement, ahead of the removal of IStyleable
pull/14761/head
Tom Edwards 2 years ago
committed by GitHub
parent
commit
16c5c24952
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 3
      src/Avalonia.Base/INamed.cs
  2. 1
      src/Avalonia.Base/StyledElement.cs
  3. 2
      src/Avalonia.Controls/Control.cs
  4. 2
      src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AddNameScopeRegistration.cs

3
src/Avalonia.Base/INamed.cs

@ -1,7 +1,8 @@
namespace Avalonia
{
/// <summary>
/// Interface for named elements.
/// Objects implementing this interface and providing a value for <see cref="Name"/> will be registered in the
/// relevant namescope when constructed in XAML.
/// </summary>
public interface INamed
{

1
src/Avalonia.Base/StyledElement.cs

@ -33,6 +33,7 @@ namespace Avalonia
ISetLogicalParent,
ISetInheritanceParent,
ISupportInitialize,
INamed,
#pragma warning disable CS0618 // Type or member is obsolete
IStyleable
#pragma warning restore CS0618 // Type or member is obsolete

2
src/Avalonia.Controls/Control.cs

@ -24,7 +24,7 @@ namespace Avalonia.Controls
/// - A <see cref="Tag"/> property to allow user-defined data to be attached to the control.
/// - <see cref="ContextRequestedEvent"/> and other context menu related members.
/// </remarks>
public class Control : InputElement, IDataTemplateHost, INamed, IVisualBrushInitialize, ISetterValue
public class Control : InputElement, IDataTemplateHost, IVisualBrushInitialize, ISetterValue
{
/// <summary>
/// Defines the <see cref="FocusAdorner"/> property.

2
src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AddNameScopeRegistration.cs

@ -16,7 +16,7 @@ namespace Avalonia.Markup.Xaml.XamlIl.CompilerExtensions.Transformers
if (node is XamlPropertyAssignmentNode pa)
{
if (pa.Property.Name == "Name"
&& pa.Property.DeclaringType.FullName == "Avalonia.StyledElement")
&& pa.Property.DeclaringType.Interfaces.Any(t => t.FullName == "Avalonia.INamed"))
{
if (context.ParentNodes().FirstOrDefault() is XamlManipulationGroupNode mg
&& mg.Children.OfType<AvaloniaNameScopeRegistrationXamlIlNode>().Any())

Loading…
Cancel
Save