diff --git a/src/Avalonia.Controls/Templates/FuncTemplate`1.cs b/src/Avalonia.Controls/Templates/FuncTemplate`1.cs index c04b08de4d..88321ee1a3 100644 --- a/src/Avalonia.Controls/Templates/FuncTemplate`1.cs +++ b/src/Avalonia.Controls/Templates/FuncTemplate`1.cs @@ -2,6 +2,7 @@ // Licensed under the MIT license. See licence.md file in the project root for full license information. using System; +using Avalonia.Styling; namespace Avalonia.Controls.Templates { @@ -34,5 +35,7 @@ namespace Avalonia.Controls.Templates { return _func(); } + + object ITemplate.Build() => Build(); } } \ No newline at end of file diff --git a/src/Avalonia.Controls/Templates/ITemplate`1.cs b/src/Avalonia.Controls/Templates/ITemplate`1.cs index 79c6ae47ba..2bf4b5a285 100644 --- a/src/Avalonia.Controls/Templates/ITemplate`1.cs +++ b/src/Avalonia.Controls/Templates/ITemplate`1.cs @@ -1,13 +1,15 @@ // 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 Avalonia.Styling; + namespace Avalonia.Controls { /// /// Creates a control. /// /// The type of control. - public interface ITemplate where TControl : IControl + public interface ITemplate : ITemplate where TControl : IControl { /// /// Creates the control. @@ -15,6 +17,6 @@ namespace Avalonia.Controls /// /// The created control. /// - TControl Build(); + new TControl Build(); } } \ No newline at end of file diff --git a/src/Avalonia.Styling/Avalonia.Styling.csproj b/src/Avalonia.Styling/Avalonia.Styling.csproj index d40627a16e..6a32441ad6 100644 --- a/src/Avalonia.Styling/Avalonia.Styling.csproj +++ b/src/Avalonia.Styling/Avalonia.Styling.csproj @@ -1,4 +1,4 @@ - + @@ -49,6 +49,7 @@ + diff --git a/src/Avalonia.Styling/Styling/ITemplate.cs b/src/Avalonia.Styling/Styling/ITemplate.cs new file mode 100644 index 0000000000..1593326e37 --- /dev/null +++ b/src/Avalonia.Styling/Styling/ITemplate.cs @@ -0,0 +1,10 @@ +// 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. + +namespace Avalonia.Styling +{ + public interface ITemplate + { + object Build(); + } +} diff --git a/src/Avalonia.Styling/Styling/Setter.cs b/src/Avalonia.Styling/Styling/Setter.cs index 09faf37360..1d45f22b65 100644 --- a/src/Avalonia.Styling/Styling/Setter.cs +++ b/src/Avalonia.Styling/Styling/Setter.cs @@ -19,6 +19,8 @@ namespace Avalonia.Styling /// public class Setter : ISetter { + private object _value; + /// /// Initializes a new instance of the class. /// @@ -54,8 +56,22 @@ namespace Avalonia.Styling [DependsOn(nameof(Property))] public object Value { - get; - set; + get + { + return _value; + } + + set + { + if (value is IStyleable) + { + throw new ArgumentException( + "Cannot assign a control to Style.Value. Wrap the control in a