Browse Source
Merge pull request #4446 from AvaloniaUI/fixes/4403-setter-binding-unsetvalue
Correctly handle UnsetValue/DoNothing in binding setters.
pull/4478/head
danwalmsley
6 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
16 additions and
1 deletions
-
src/Avalonia.Styling/Styling/PropertySetterBindingInstance.cs
-
tests/Avalonia.Styling.UnitTests/SetterTests.cs
|
|
|
@ -164,7 +164,7 @@ namespace Avalonia.Styling |
|
|
|
|
|
|
|
private void ConvertAndPublishNext(object? value) |
|
|
|
{ |
|
|
|
_value = value is T v ? v : BindingValue<T>.FromUntyped(value); |
|
|
|
_value = BindingValue<T>.FromUntyped(value); |
|
|
|
|
|
|
|
if (_isActive) |
|
|
|
{ |
|
|
|
|
|
|
|
@ -35,6 +35,21 @@ namespace Avalonia.Styling.UnitTests |
|
|
|
Assert.Equal("foo", control.Text); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Setter_Should_Handle_Binding_Producing_UnsetValue() |
|
|
|
{ |
|
|
|
var control = new TextBlock(); |
|
|
|
var subject = new BehaviorSubject<object>(AvaloniaProperty.UnsetValue); |
|
|
|
var descriptor = InstancedBinding.OneWay(subject); |
|
|
|
var binding = Mock.Of<IBinding>(x => x.Initiate(control, TextBlock.TagProperty, null, false) == descriptor); |
|
|
|
var style = Mock.Of<IStyle>(); |
|
|
|
var setter = new Setter(TextBlock.TagProperty, binding); |
|
|
|
|
|
|
|
setter.Instance(control).Start(false); |
|
|
|
|
|
|
|
Assert.Equal("", control.Text); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Setter_Should_Materialize_Template_To_Property() |
|
|
|
{ |
|
|
|
|