diff --git a/src/Avalonia.Base/StyledElement.cs b/src/Avalonia.Base/StyledElement.cs index 711d17d014..d1b960390c 100644 --- a/src/Avalonia.Base/StyledElement.cs +++ b/src/Avalonia.Base/StyledElement.cs @@ -21,7 +21,6 @@ namespace Avalonia /// Extends an with the following features: /// /// - An inherited . - /// - Implements to allow styling to work on the styled element. /// - Implements to form part of a logical tree. /// - A collection of class strings for custom styling. /// @@ -35,10 +34,7 @@ namespace Avalonia ISetInheritanceParent, ISupportInitialize, INamed, - IAvaloniaListItemValidator, -#pragma warning disable CS0618 // Type or member is obsolete - IStyleable -#pragma warning restore CS0618 // Type or member is obsolete + IAvaloniaListItemValidator { /// /// Defines the property. @@ -330,9 +326,6 @@ namespace Avalonia bool IResourceNode.HasResources => (_resources?.HasResources ?? false) || (((IResourceNode?)_styles)?.HasResources ?? false); - /// - IAvaloniaReadOnlyList IStyleable.Classes => Classes; - /// bool IStyleHost.IsStylesInitialized => _styles != null; @@ -668,7 +661,7 @@ namespace Avalonia // If the Theme property is not set, try to find a ControlTheme resource with our StyleKey. if (_implicitTheme is null) { - var key = GetStyleKey(this); + var key = StyleKey; if (this.TryFindResource(key, out var value) && value is ControlTheme t) _implicitTheme = t; @@ -699,22 +692,6 @@ namespace Avalonia } } - /// - /// Internal getter for so that we only need to suppress the obsolete - /// warning in one place. - /// - /// The element - /// - /// is obsolete and will be removed in a future version, but for backwards - /// compatibility we need to support code which overrides . - /// - internal static Type GetStyleKey(StyledElement e) - { -#pragma warning disable CS0618 // Type or member is obsolete - return ((IStyleable)e).StyleKey; -#pragma warning restore CS0618 // Type or member is obsolete - } - private static void DataContextNotifying(AvaloniaObject o, bool updateStarted) { if (o is StyledElement element) diff --git a/src/Avalonia.Base/Styling/ControlTheme.cs b/src/Avalonia.Base/Styling/ControlTheme.cs index fbd869a9a7..138c2f9de5 100644 --- a/src/Avalonia.Base/Styling/ControlTheme.cs +++ b/src/Avalonia.Base/Styling/ControlTheme.cs @@ -50,7 +50,7 @@ namespace Avalonia.Styling using var activity = Diagnostic.AttachingStyle()? .AddTag(Diagnostic.Tags.Style, this); - if (HasSettersOrAnimations && TargetType.IsAssignableFrom(StyledElement.GetStyleKey(target))) + if (HasSettersOrAnimations && TargetType.IsAssignableFrom(target.StyleKey)) { Attach(target, null, type, true); activity?.AddTag(Diagnostic.Tags.SelectorResult, SelectorMatchResult.AlwaysThisType); diff --git a/src/Avalonia.Base/Styling/IStyleable.cs b/src/Avalonia.Base/Styling/IStyleable.cs deleted file mode 100644 index 0768669905..0000000000 --- a/src/Avalonia.Base/Styling/IStyleable.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; -using Avalonia.Collections; - -namespace Avalonia.Styling -{ - /// - /// Interface for styleable elements. - /// - [Obsolete("This interface may be removed in 12.0. Use StyledElement, or override StyledElement.StyleKeyOverride to override the StyleKey for a class.")] - public interface IStyleable : INamed - { - /// - /// Gets the list of classes for the control. - /// - IAvaloniaReadOnlyList Classes { get; } - - /// - /// Gets the type by which the control is styled. - /// - [Obsolete("Override StyledElement.StyleKeyOverride instead.")] - Type StyleKey { get; } - - /// - /// Gets the template parent of this element if the control comes from a template. - /// - AvaloniaObject? TemplatedParent { get; } - } -} diff --git a/src/Avalonia.Base/Styling/NestingSelector.cs b/src/Avalonia.Base/Styling/NestingSelector.cs index 4f6920c224..07fc24b644 100644 --- a/src/Avalonia.Base/Styling/NestingSelector.cs +++ b/src/Avalonia.Base/Styling/NestingSelector.cs @@ -23,7 +23,7 @@ namespace Avalonia.Styling { if (theme.TargetType is null) throw new InvalidOperationException("ControlTheme has no TargetType."); - return theme.TargetType.IsAssignableFrom(StyledElement.GetStyleKey(control)) ? + return theme.TargetType.IsAssignableFrom(control.StyleKey) ? SelectorMatch.AlwaysThisType : SelectorMatch.NeverThisType; } @@ -31,7 +31,7 @@ namespace Avalonia.Styling { if (queryTheme.TargetType is null) throw new InvalidOperationException("ControlTheme has no TargetType."); - return queryTheme.TargetType.IsAssignableFrom(StyledElement.GetStyleKey(control)) ? + return queryTheme.TargetType.IsAssignableFrom(control.StyleKey) ? SelectorMatch.AlwaysThisType : SelectorMatch.NeverThisType; } diff --git a/src/Avalonia.Base/Styling/TypeNameAndClassSelector.cs b/src/Avalonia.Base/Styling/TypeNameAndClassSelector.cs index 4fba8c02c6..4f78d91a38 100644 --- a/src/Avalonia.Base/Styling/TypeNameAndClassSelector.cs +++ b/src/Avalonia.Base/Styling/TypeNameAndClassSelector.cs @@ -93,7 +93,7 @@ namespace Avalonia.Styling { if (TargetType != null) { - var controlType = StyledElement.GetStyleKey(control) ?? control.GetType(); + var controlType = control.StyleKey ?? control.GetType(); if (IsConcreteType) { diff --git a/src/Avalonia.Controls/ItemsControl.cs b/src/Avalonia.Controls/ItemsControl.cs index 0c3e908bbf..a9cf4ca8d8 100644 --- a/src/Avalonia.Controls/ItemsControl.cs +++ b/src/Avalonia.Controls/ItemsControl.cs @@ -720,7 +720,7 @@ namespace Avalonia.Controls { var itemContainerTheme = ItemContainerTheme; - if (itemContainerTheme?.TargetType?.IsAssignableFrom(GetStyleKey(container)) == true) + if (itemContainerTheme?.TargetType?.IsAssignableFrom(container.StyleKey) == true) { // We have an ItemContainerTheme and it matches the container. Set the Theme // property, and mark the container as having had ItemContainerTheme applied.