Browse Source
Merge pull request #3359 from jp2masa/target-null-value
Fixed BindingExtension.TargetNullValue default value
pull/3363/head
Dariusz Komosiński
7 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
25 additions and
3 deletions
-
src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/BindingExtension.cs
-
tests/Avalonia.Markup.Xaml.UnitTests/MarkupExtensions/BindingExtensionTests.cs
|
|
|
@ -87,7 +87,7 @@ namespace Avalonia.Markup.Xaml.MarkupExtensions |
|
|
|
public string StringFormat { get; set; } |
|
|
|
|
|
|
|
public RelativeSource RelativeSource { get; set; } |
|
|
|
|
|
|
|
public object TargetNullValue { get; set; } |
|
|
|
|
|
|
|
public object TargetNullValue { get; set; } = AvaloniaProperty.UnsetValue; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -38,7 +38,7 @@ namespace Avalonia.Markup.Xaml.UnitTests.MarkupExtensions |
|
|
|
Assert.Equal("foobar", textBlock.Text); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void BindingExtension_Binds_To_TargetNullValue() |
|
|
|
{ |
|
|
|
@ -65,6 +65,28 @@ namespace Avalonia.Markup.Xaml.UnitTests.MarkupExtensions |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void BindingExtension_TargetNullValue_UnsetByDefault() |
|
|
|
{ |
|
|
|
using (StyledWindow()) |
|
|
|
{ |
|
|
|
var xaml = @"
|
|
|
|
<Window xmlns='https://github.com/avaloniaui'
|
|
|
|
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
|
|
|
|
<TextBlock Name='textBlock' IsVisible='{Binding Foo, Converter={x:Static ObjectConverters.IsNotNull}}'/> |
|
|
|
</Window>";
|
|
|
|
|
|
|
|
var loader = new AvaloniaXamlLoader(); |
|
|
|
var window = (Window)loader.Load(xaml); |
|
|
|
var textBlock = window.FindControl<TextBlock>("textBlock"); |
|
|
|
|
|
|
|
window.DataContext = new FooBar(); |
|
|
|
window.Show(); |
|
|
|
|
|
|
|
Assert.Equal(false, textBlock.IsVisible); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private class FooBar |
|
|
|
{ |
|
|
|
public object Foo { get; } = null; |
|
|
|
|