Browse Source
Merge pull request #3348 from pr8x/fix-TargetNullValue-xaml
Adding TargetNullValue to BindingExtension
pull/3359/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
34 additions and
0 deletions
-
src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/BindingExtension.cs
-
tests/Avalonia.Markup.Xaml.UnitTests/MarkupExtensions/BindingExtensionTests.cs
|
|
|
@ -41,6 +41,7 @@ namespace Avalonia.Markup.Xaml.MarkupExtensions |
|
|
|
StringFormat = StringFormat, |
|
|
|
RelativeSource = RelativeSource, |
|
|
|
DefaultAnchor = new WeakReference(GetDefaultAnchor(descriptorContext)), |
|
|
|
TargetNullValue = TargetNullValue, |
|
|
|
NameScope = new WeakReference<INameScope>(serviceProvider.GetService<INameScope>()) |
|
|
|
}; |
|
|
|
} |
|
|
|
@ -86,5 +87,7 @@ namespace Avalonia.Markup.Xaml.MarkupExtensions |
|
|
|
public string StringFormat { get; set; } |
|
|
|
|
|
|
|
public RelativeSource RelativeSource { get; set; } |
|
|
|
|
|
|
|
public object TargetNullValue { get; set; } |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -38,6 +38,37 @@ namespace Avalonia.Markup.Xaml.UnitTests.MarkupExtensions |
|
|
|
Assert.Equal("foobar", textBlock.Text); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void BindingExtension_Binds_To_TargetNullValue() |
|
|
|
{ |
|
|
|
using (StyledWindow()) |
|
|
|
{ |
|
|
|
var xaml = @"
|
|
|
|
<Window xmlns='https://github.com/avaloniaui'
|
|
|
|
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
|
|
|
|
<Window.Resources> |
|
|
|
<x:String x:Key='text'>foobar</x:String> |
|
|
|
</Window.Resources> |
|
|
|
|
|
|
|
<TextBlock Name='textBlock' Text='{Binding Foo, TargetNullValue={StaticResource text}}'/> |
|
|
|
</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("foobar", textBlock.Text); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private class FooBar |
|
|
|
{ |
|
|
|
public object Foo { get; } = null; |
|
|
|
} |
|
|
|
|
|
|
|
private IDisposable StyledWindow(params (string, string)[] assets) |
|
|
|
{ |
|
|
|
|