diff --git a/src/Perspex.Styling/Styling/Setter.cs b/src/Perspex.Styling/Styling/Setter.cs
index 0db359fa40..e93729cf6e 100644
--- a/src/Perspex.Styling/Styling/Setter.cs
+++ b/src/Perspex.Styling/Styling/Setter.cs
@@ -62,15 +62,53 @@ namespace Perspex.Styling
/// An optional activator.
public void Apply(IStyle style, IStyleable control, IObservable activator)
{
- if (activator == null)
+ if (Property == null)
{
- control.SetValue(Property, Value, BindingPriority.Style);
+ throw new InvalidOperationException("Setter.Property must be set.");
+ }
+
+ var binding = Value as IBinding;
+
+ if (binding != null)
+ {
+ if (activator == null)
+ {
+ Bind(control, Property, binding);
+ }
+ else
+ {
+ throw new NotSupportedException(
+ "Setter bindings with activators not yet supported.");
+ }
}
else
{
- var binding = new StyleBinding(activator, Value, style.ToString());
- control.Bind(Property, binding, BindingPriority.StyleTrigger);
+ if (activator == null)
+ {
+ control.SetValue(Property, Value, BindingPriority.Style);
+ }
+ else
+ {
+ var activated = new StyleBinding(activator, Value, style.ToString());
+ control.Bind(Property, activated, BindingPriority.StyleTrigger);
+ }
}
}
+
+ private void Bind(IStyleable control, PerspexProperty property, IBinding binding)
+ {
+ var mode = binding.Mode;
+
+ if (mode == BindingMode.Default)
+ {
+ mode = property.DefaultBindingMode;
+ }
+
+ control.Bind(
+ property,
+ binding.CreateSubject(control, property),
+ mode,
+ binding.Priority);
+ }
}
}
diff --git a/tests/Perspex.Styling.UnitTests/Perspex.Styling.UnitTests.csproj b/tests/Perspex.Styling.UnitTests/Perspex.Styling.UnitTests.csproj
index cc22e7f257..b9e82d589d 100644
--- a/tests/Perspex.Styling.UnitTests/Perspex.Styling.UnitTests.csproj
+++ b/tests/Perspex.Styling.UnitTests/Perspex.Styling.UnitTests.csproj
@@ -91,6 +91,7 @@
+
diff --git a/tests/Perspex.Styling.UnitTests/SetterTests.cs b/tests/Perspex.Styling.UnitTests/SetterTests.cs
new file mode 100644
index 0000000000..c42426e97b
--- /dev/null
+++ b/tests/Perspex.Styling.UnitTests/SetterTests.cs
@@ -0,0 +1,28 @@
+// Copyright (c) The Perspex Project. All rights reserved.
+// Licensed under the MIT license. See licence.md file in the project root for full license information.
+
+using System.Reactive.Subjects;
+using Moq;
+using Perspex.Controls;
+using Perspex.Data;
+using Xunit;
+
+namespace Perspex.Styling.UnitTests
+{
+ public class SetterTests
+ {
+ [Fact]
+ public void Setter_Should_Apply_Binding_To_Property()
+ {
+ var control = new TextBlock();
+ var subject = new BehaviorSubject