diff --git a/src/Avalonia.Controls/Control.cs b/src/Avalonia.Controls/Control.cs
index a7ee027e70..ca5edae4a9 100644
--- a/src/Avalonia.Controls/Control.cs
+++ b/src/Avalonia.Controls/Control.cs
@@ -1,6 +1,7 @@
// Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
+using System;
using System.ComponentModel;
using Avalonia.Controls.Primitives;
using Avalonia.Controls.Templates;
@@ -20,7 +21,7 @@ namespace Avalonia.Controls
///
/// - A property to allow user-defined data to be attached to the control.
///
- public class Control : InputElement, IControl, INamed, ISupportInitialize, IVisualBrushInitialize, IRequiresTemplateInSetter
+ public class Control : InputElement, IControl, INamed, ISupportInitialize, IVisualBrushInitialize, ISetterValue
{
///
/// Defines the property.
@@ -90,6 +91,13 @@ namespace Avalonia.Controls
///
bool IDataTemplateHost.IsDataTemplatesInitialized => _dataTemplates != null;
+ ///
+ void ISetterValue.Initialize(ISetter setter)
+ {
+ throw new InvalidOperationException(
+ "Cannot use a control as a Setter value. Wrap the control in a .");
+ }
+
///
void IVisualBrushInitialize.EnsureInitialized()
{
diff --git a/src/Avalonia.Styling/Styling/IRequiresTemplateInSetter.cs b/src/Avalonia.Styling/Styling/IRequiresTemplateInSetter.cs
deleted file mode 100644
index 2d562b78d9..0000000000
--- a/src/Avalonia.Styling/Styling/IRequiresTemplateInSetter.cs
+++ /dev/null
@@ -1,10 +0,0 @@
-namespace Avalonia.Styling
-{
- ///
- /// This is an interface for advanced scenarios to assist users in correct style development.
- /// You as a user will not need to use this interface directly.
- ///
- public interface IRequiresTemplateInSetter
- {
- }
-}
diff --git a/src/Avalonia.Styling/Styling/ISetterValue.cs b/src/Avalonia.Styling/Styling/ISetterValue.cs
new file mode 100644
index 0000000000..63c544cf7d
--- /dev/null
+++ b/src/Avalonia.Styling/Styling/ISetterValue.cs
@@ -0,0 +1,13 @@
+namespace Avalonia.Styling
+{
+ ///
+ /// Customizes the behavior of a class when added as a value to an .
+ ///
+ public interface ISetterValue
+ {
+ ///
+ /// Notifies that the object has been added as a setter value.
+ ///
+ void Initialize(ISetter setter);
+ }
+}
diff --git a/src/Avalonia.Styling/Styling/Setter.cs b/src/Avalonia.Styling/Styling/Setter.cs
index cfe17a4291..3702259f35 100644
--- a/src/Avalonia.Styling/Styling/Setter.cs
+++ b/src/Avalonia.Styling/Styling/Setter.cs
@@ -65,13 +65,7 @@ namespace Avalonia.Styling
set
{
- if (value is IRequiresTemplateInSetter)
- {
- throw new ArgumentException(
- "Cannot assign a control to Setter.Value. Wrap the control in a .",
- nameof(value));
- }
-
+ (value as ISetterValue)?.Initialize(this);
_value = value;
}
}
diff --git a/src/Markup/Avalonia.Markup/Data/TemplateBinding.cs b/src/Markup/Avalonia.Markup/Data/TemplateBinding.cs
index fab9bdbf55..e64efd9df9 100644
--- a/src/Markup/Avalonia.Markup/Data/TemplateBinding.cs
+++ b/src/Markup/Avalonia.Markup/Data/TemplateBinding.cs
@@ -3,6 +3,7 @@ using System.Globalization;
using System.Reactive.Subjects;
using Avalonia.Data.Converters;
using Avalonia.Reactive;
+using Avalonia.Styling;
namespace Avalonia.Data
{
@@ -12,8 +13,10 @@ namespace Avalonia.Data
public class TemplateBinding : SingleSubscriberObservableBase