Add IAddChild to StyleBase to fix IDE errors when adding Style as children to ContainerQuery (#18800)

* Add IAddChild implementation too StyleBase

* We don't actually need to Add child in AddChild

* Revert "We don't actually need to Add child in AddChild"

This reverts commit c2cd3012ca7fb0b007872e8a1bf0f54ef3cf4cea.

* Only use IAddChild as generic ones are not needed to fix the issue

* Update XamlX with fixes for IAddChild

This reverts commit 393000cf92e16696c7d0a2688a52ec654cd62c6e.
This commit is contained in:
Wiesław Šoltés
2025-05-16 02:32:35 +02:00
committed by GitHub
parent d8f590d42e
commit a847b23f51
2 changed files with 17 additions and 2 deletions
+1 -1
+16 -1
View File
@@ -11,7 +11,7 @@ namespace Avalonia.Styling
/// <summary>
/// Base class for <see cref="Style"/> and <see cref="ControlTheme"/>.
/// </summary>
public abstract class StyleBase : AvaloniaObject, IStyle, IResourceProvider
public abstract class StyleBase : AvaloniaObject, IStyle, IResourceProvider, IAddChild
{
private IResourceHost? _owner;
private StyleChildren? _children;
@@ -72,6 +72,21 @@ namespace Avalonia.Styling
public void Add(SetterBase setter) => Setters.Add(setter);
public void Add(IStyle style) => Children.Add(style);
void IAddChild.AddChild(object child)
{
switch (child)
{
case SetterBase setter:
Setters.Add(setter);
break;
case IStyle style:
Children.Add(style);
break;
default:
throw new InvalidOperationException($"Cannot add {child.GetType()} to a style.");
}
}
public event EventHandler? OwnerChanged;
public bool TryGetResource(object key, ThemeVariant? themeVariant, out object? result)