From 2ad6d64147791d0ee0371442e6055c481a2951e8 Mon Sep 17 00:00:00 2001
From: Jumar Macato <16554748+jmacato@users.noreply.github.com>
Date: Sun, 27 Mar 2022 19:47:58 +0800
Subject: [PATCH] Merge pull request #7854 from robloo/template-part-attribute
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 0060767565..30e8661e89 100644
--- a/src/Avalonia.Styling/Controls/Metadata/PseudoClassesAttribute.cs
+++ b/src/Avalonia.Styling/Controls/Metadata/PseudoClassesAttribute.cs
@@ -5,14 +5,27 @@ using System.Collections.Generic;
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 0000000000..3b8f971713
--- /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; }
+ }
+}