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:
Vendored
+1
-1
Submodule external/XamlX updated: cbfec32876...83567b8a50
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user