Browse Source
Merge pull request #1304 from AvaloniaUI/fixes/1303-templatebinding-null-path
Don't pass a null Path to Binding in TemplateBindingExtension.
pull/1270/merge
Jeremy Koritzinsky
9 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with
56 additions and
1 deletions
-
src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/TemplateBindingExtension.cs
-
tests/Avalonia.Markup.Xaml.UnitTests/Data/BindingTests.cs
-
tests/Avalonia.Markup.Xaml.UnitTests/Data/BindingTests_TemplatedParent.cs
|
|
|
@ -29,7 +29,7 @@ namespace Avalonia.Markup.Xaml.MarkupExtensions |
|
|
|
ElementName = ElementName, |
|
|
|
Mode = Mode, |
|
|
|
RelativeSource = new RelativeSource(RelativeSourceMode.TemplatedParent), |
|
|
|
Path = Path, |
|
|
|
Path = Path ?? string.Empty, |
|
|
|
Priority = Priority, |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
@ -13,6 +13,7 @@ using Moq; |
|
|
|
using Xunit; |
|
|
|
using System.ComponentModel; |
|
|
|
using System.Runtime.CompilerServices; |
|
|
|
using Avalonia.UnitTests; |
|
|
|
|
|
|
|
namespace Avalonia.Markup.Xaml.UnitTests.Data |
|
|
|
{ |
|
|
|
@ -337,6 +338,28 @@ namespace Avalonia.Markup.Xaml.UnitTests.Data |
|
|
|
Assert.Equal("foo", target.Content); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Binding_With_Null_Path_Works() |
|
|
|
{ |
|
|
|
using (UnitTestApplication.Start(TestServices.StyledWindow)) |
|
|
|
{ |
|
|
|
var xaml = @"
|
|
|
|
<Window xmlns='https://github.com/avaloniaui'
|
|
|
|
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'
|
|
|
|
xmlns:local='clr-namespace:Avalonia.Markup.Xaml.UnitTests.Xaml;assembly=Avalonia.Markup.Xaml.UnitTests'> |
|
|
|
<TextBlock Name='textBlock' Text='{Binding}'/> |
|
|
|
</Window>";
|
|
|
|
var loader = new AvaloniaXamlLoader(); |
|
|
|
var window = (Window)loader.Load(xaml); |
|
|
|
var textBlock = window.FindControl<TextBlock>("textBlock"); |
|
|
|
|
|
|
|
window.DataContext = "foo"; |
|
|
|
window.ApplyTemplate(); |
|
|
|
|
|
|
|
Assert.Equal("foo", textBlock.Text); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private class TwoWayBindingTest : Control |
|
|
|
{ |
|
|
|
public static readonly StyledProperty<string> TwoWayProperty = |
|
|
|
|
|
|
|
@ -11,6 +11,9 @@ using Avalonia.Markup.Xaml.Data; |
|
|
|
using Avalonia.Styling; |
|
|
|
using Xunit; |
|
|
|
using System.Reactive.Disposables; |
|
|
|
using Avalonia.UnitTests; |
|
|
|
using Avalonia.VisualTree; |
|
|
|
using System.Linq; |
|
|
|
|
|
|
|
namespace Avalonia.Markup.Xaml.UnitTests.Data |
|
|
|
{ |
|
|
|
@ -56,6 +59,35 @@ namespace Avalonia.Markup.Xaml.UnitTests.Data |
|
|
|
BindingPriority.TemplatedParent)); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void TemplateBinding_With_Null_Path_Works() |
|
|
|
{ |
|
|
|
using (UnitTestApplication.Start(TestServices.StyledWindow)) |
|
|
|
{ |
|
|
|
var xaml = @"
|
|
|
|
<Window xmlns='https://github.com/avaloniaui'
|
|
|
|
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'
|
|
|
|
xmlns:local='clr-namespace:Avalonia.Markup.Xaml.UnitTests.Xaml;assembly=Avalonia.Markup.Xaml.UnitTests'> |
|
|
|
<Button Name='button'> |
|
|
|
<Button.Template> |
|
|
|
<ControlTemplate> |
|
|
|
<TextBlock Text='{TemplateBinding}'/> |
|
|
|
</ControlTemplate> |
|
|
|
</Button.Template> |
|
|
|
</Button> |
|
|
|
</Window>";
|
|
|
|
var loader = new AvaloniaXamlLoader(); |
|
|
|
var window = (Window)loader.Load(xaml); |
|
|
|
var button = window.FindControl<Button>("button"); |
|
|
|
|
|
|
|
window.ApplyTemplate(); |
|
|
|
button.ApplyTemplate(); |
|
|
|
|
|
|
|
var textBlock = (TextBlock)button.GetVisualChildren().Single(); |
|
|
|
Assert.Equal("Avalonia.Controls.Button", textBlock.Text); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private Mock<IControl> CreateTarget( |
|
|
|
ITemplatedControl templatedParent = null, |
|
|
|
string text = null) |
|
|
|
|