From 708759584936f21a14b7b88fc9aab4ce456d3225 Mon Sep 17 00:00:00 2001
From: Tom Edwards <109803929+TomEdwardsEnscape@users.noreply.github.com>
Date: Fri, 14 Mar 2025 07:47:26 +0100
Subject: [PATCH] Extend diagnostic TreeNode features to more types (#18430)
- Display the name of any INamed
- Display the classes of any StyledElement
Removed stale documentation about nonexistent StyledElement.Clasess setter
---
src/Avalonia.Base/StyledElement.cs | 6 ------
.../Diagnostics/ViewModels/TreeNode.cs | 19 +++++++++----------
2 files changed, 9 insertions(+), 16 deletions(-)
diff --git a/src/Avalonia.Base/StyledElement.cs b/src/Avalonia.Base/StyledElement.cs
index 1f0c00ef63..3e57a1a959 100644
--- a/src/Avalonia.Base/StyledElement.cs
+++ b/src/Avalonia.Base/StyledElement.cs
@@ -180,12 +180,6 @@ namespace Avalonia
/// Classes can be used to apply user-defined styling to styled elements, or to allow styled elements
/// that share a common purpose to be easily selected.
///
- ///
- /// Even though this property can be set, the setter is only intended for use in object
- /// initializers. Assigning to this property does not change the underlying collection,
- /// it simply clears the existing collection and adds the contents of the assigned
- /// collection.
- ///
///
public Classes Classes => _classes ??= new();
diff --git a/src/Avalonia.Diagnostics/Diagnostics/ViewModels/TreeNode.cs b/src/Avalonia.Diagnostics/Diagnostics/ViewModels/TreeNode.cs
index aafaa096e3..0b94fe6f85 100644
--- a/src/Avalonia.Diagnostics/Diagnostics/ViewModels/TreeNode.cs
+++ b/src/Avalonia.Diagnostics/Diagnostics/ViewModels/TreeNode.cs
@@ -15,26 +15,25 @@ namespace Avalonia.Diagnostics.ViewModels
private string _classes;
private bool _isExpanded;
- protected TreeNode(AvaloniaObject avaloniaObject, TreeNode? parent, string? customName = null)
+ protected TreeNode(AvaloniaObject avaloniaObject, TreeNode? parent, string? customTypeName = null)
{
_classes = string.Empty;
Parent = parent;
- var visual = avaloniaObject ;
- Type = customName ?? avaloniaObject.GetType().Name;
- Visual = visual!;
+ Type = customTypeName ?? avaloniaObject.GetType().Name;
+ Visual = avaloniaObject;
FontWeight = IsRoot ? FontWeight.Bold : FontWeight.Normal;
- if (visual is Control control)
- {
- ElementName = control.Name;
+ ElementName = (avaloniaObject as INamed)?.Name;
- _classesSubscription = ((IObservable