Skip to content

Commit 7087595

Browse files
authoredMar 14, 2025
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
1 parent fb5121a commit 7087595

File tree

2 files changed

+9
-16
lines changed

2 files changed

+9
-16
lines changed
 

‎src/Avalonia.Base/StyledElement.cs

-6
Original file line numberDiff line numberDiff line change
@@ -180,12 +180,6 @@ public string? Name
180180
/// Classes can be used to apply user-defined styling to styled elements, or to allow styled elements
181181
/// that share a common purpose to be easily selected.
182182
/// </para>
183-
/// <para>
184-
/// Even though this property can be set, the setter is only intended for use in object
185-
/// initializers. Assigning to this property does not change the underlying collection,
186-
/// it simply clears the existing collection and adds the contents of the assigned
187-
/// collection.
188-
/// </para>
189183
/// </remarks>
190184
public Classes Classes => _classes ??= new();
191185

‎src/Avalonia.Diagnostics/Diagnostics/ViewModels/TreeNode.cs

+9-10
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,25 @@ internal abstract class TreeNode : ViewModelBase, IDisposable
1515
private string _classes;
1616
private bool _isExpanded;
1717

18-
protected TreeNode(AvaloniaObject avaloniaObject, TreeNode? parent, string? customName = null)
18+
protected TreeNode(AvaloniaObject avaloniaObject, TreeNode? parent, string? customTypeName = null)
1919
{
2020
_classes = string.Empty;
2121
Parent = parent;
22-
var visual = avaloniaObject ;
23-
Type = customName ?? avaloniaObject.GetType().Name;
24-
Visual = visual!;
22+
Type = customTypeName ?? avaloniaObject.GetType().Name;
23+
Visual = avaloniaObject;
2524
FontWeight = IsRoot ? FontWeight.Bold : FontWeight.Normal;
2625

27-
if (visual is Control control)
28-
{
29-
ElementName = control.Name;
26+
ElementName = (avaloniaObject as INamed)?.Name;
3027

31-
_classesSubscription = ((IObservable<object?>)control.Classes.GetWeakCollectionChangedObservable())
28+
if (avaloniaObject is StyledElement { Classes: { } classes })
29+
{
30+
_classesSubscription = ((IObservable<object?>)classes.GetWeakCollectionChangedObservable())
3231
.StartWith(null)
3332
.Subscribe(_ =>
3433
{
35-
if (control.Classes.Count > 0)
34+
if (classes.Count > 0)
3635
{
37-
Classes = "(" + string.Join(" ", control.Classes) + ")";
36+
Classes = $"({string.Join(" ", classes)})";
3837
}
3938
else
4039
{

0 commit comments

Comments
 (0)