From 6a1e7b25a75e312e1a93d3a0192382eaca9ddd38 Mon Sep 17 00:00:00 2001 From: robloo Date: Tue, 22 Mar 2022 18:26:25 -0400 Subject: [PATCH] Implement TemplatePartAttribute from WPF --- .../Metadata/PseudoClassesAttribute.cs | 13 +++++ .../Metadata/TemplatePartAttribute.cs | 55 +++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 src/Avalonia.Styling/Controls/Metadata/TemplatePartAttribute.cs diff --git a/src/Avalonia.Styling/Controls/Metadata/PseudoClassesAttribute.cs b/src/Avalonia.Styling/Controls/Metadata/PseudoClassesAttribute.cs index 0060767565d..30e8661e896 100644 --- a/src/Avalonia.Styling/Controls/Metadata/PseudoClassesAttribute.cs +++ b/src/Avalonia.Styling/Controls/Metadata/PseudoClassesAttribute.cs @@ -5,14 +5,27 @@ namespace Avalonia.Controls.Metadata { + /// + /// Defines all pseudoclasses by name referenced and implemented by a control. + /// + /// + /// This is currently used for code-completion in certain IDEs. + /// [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] public sealed class PseudoClassesAttribute : Attribute { + /// + /// Initializes a new instance of the class. + /// + /// The list of pseudoclass names. public PseudoClassesAttribute(params string[] pseudoClasses) { PseudoClasses = pseudoClasses; } + /// + /// Gets the list of pseudoclass names. + /// public IReadOnlyList PseudoClasses { get; } } } diff --git a/src/Avalonia.Styling/Controls/Metadata/TemplatePartAttribute.cs b/src/Avalonia.Styling/Controls/Metadata/TemplatePartAttribute.cs new file mode 100644 index 00000000000..3b8f9717139 --- /dev/null +++ b/src/Avalonia.Styling/Controls/Metadata/TemplatePartAttribute.cs @@ -0,0 +1,55 @@ +// This source file is adapted from the Windows Presentation Foundation project. +// (https://github.com/dotnet/wpf/) +// +// Licensed to The Avalonia Project under MIT License, courtesy of The .NET Foundation. + +using System; + +#nullable enable + +namespace Avalonia.Controls.Metadata +{ + /// + /// Defines a control template part referenced by name in code. + /// Template part names should begin with the "PART_" prefix. + /// + /// + /// Style authors should be able to identify the part type used for styling the specific control. + /// The part is usually required in the style and should have a specific predefined name. + /// + [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] + public sealed class TemplatePartAttribute : Attribute + { + /// + /// Initializes a new instance of the class. + /// + public TemplatePartAttribute() + { + Name = string.Empty; + Type = typeof(object); + } + + /// + /// Initializes a new instance of the class. + /// + /// The part name used by the class to identify a required element in the style. + /// The type of the element that should be used as a part with name. + public TemplatePartAttribute(string name, Type type) + { + Name = name; + Type = type; + } + + /// + /// Gets or sets the part name used by the class to identify a required element in the style. + /// Template part names should begin with the "PART_" prefix. + /// + public string Name { get; set; } + + /// + /// Gets or sets the type of the element that should be used as a part with name specified + /// in . + /// + public Type Type { get; set; } + } +}