|
|
|
@ -3,6 +3,7 @@ |
|
|
|
|
|
|
|
using Avalonia.Controls; |
|
|
|
using Avalonia.UnitTests; |
|
|
|
using System; |
|
|
|
using Xunit; |
|
|
|
|
|
|
|
namespace Avalonia.Markup.Xaml.UnitTests.Xaml |
|
|
|
@ -77,6 +78,77 @@ namespace Avalonia.Markup.Xaml.UnitTests.Xaml |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Binding_To_First_Ancestor_Without_AncestorType_Throws_Exception() |
|
|
|
{ |
|
|
|
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'> |
|
|
|
<Border Name='border1'> |
|
|
|
<ContentControl Name='contentControl'> |
|
|
|
<Button Name='button' Content='{Binding Name, RelativeSource={RelativeSource AncestorLevel=1}}'/> |
|
|
|
</ContentControl> |
|
|
|
</Border> |
|
|
|
</Window>";
|
|
|
|
var loader = new AvaloniaXamlLoader(); |
|
|
|
Assert.Throws<InvalidOperationException>( () => loader.Load(xaml)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Binding_To_First_Ancestor_With_Shorthand_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'> |
|
|
|
<Border Name='border1'> |
|
|
|
<Border Name='border2'> |
|
|
|
<Button Name='button' Content='{Binding $parent.Name}'/> |
|
|
|
</Border> |
|
|
|
</Border> |
|
|
|
</Window>";
|
|
|
|
var loader = new AvaloniaXamlLoader(); |
|
|
|
var window = (Window)loader.Load(xaml); |
|
|
|
var button = window.FindControl<Button>("button"); |
|
|
|
|
|
|
|
window.ApplyTemplate(); |
|
|
|
|
|
|
|
Assert.Equal("border2", button.Content); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Binding_To_First_Ancestor_With_Shorthand_Uses_LogicalTree() |
|
|
|
{ |
|
|
|
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'> |
|
|
|
<Border Name='border'> |
|
|
|
<ContentControl Name='contentControl'> |
|
|
|
<Button Name='button' Content='{Binding $parent.Name}'/> |
|
|
|
</ContentControl> |
|
|
|
</Border> |
|
|
|
</Window>";
|
|
|
|
var loader = new AvaloniaXamlLoader(); |
|
|
|
var window = (Window)loader.Load(xaml); |
|
|
|
var contentControl = window.FindControl<ContentControl>("contentControl"); |
|
|
|
var button = window.FindControl<Button>("button"); |
|
|
|
|
|
|
|
window.ApplyTemplate(); |
|
|
|
|
|
|
|
Assert.Equal("contentControl", button.Content); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Binding_To_Second_Ancestor_Works() |
|
|
|
{ |
|
|
|
@ -102,6 +174,108 @@ namespace Avalonia.Markup.Xaml.UnitTests.Xaml |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Binding_To_Second_Ancestor_With_Shorthand_Uses_LogicalTree() |
|
|
|
{ |
|
|
|
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'> |
|
|
|
<ContentControl Name='contentControl1'> |
|
|
|
<ContentControl Name='contentControl2'> |
|
|
|
<Button Name='button' Content='{Binding $parent[1].Name}'/> |
|
|
|
</ContentControl> |
|
|
|
</ContentControl> |
|
|
|
</Window>";
|
|
|
|
var loader = new AvaloniaXamlLoader(); |
|
|
|
var window = (Window)loader.Load(xaml); |
|
|
|
var contentControl1 = window.FindControl<ContentControl>("contentControl1"); |
|
|
|
var contentControl2 = window.FindControl<ContentControl>("contentControl2"); |
|
|
|
var button = window.FindControl<Button>("button"); |
|
|
|
|
|
|
|
window.ApplyTemplate(); |
|
|
|
|
|
|
|
Assert.Equal("contentControl1", button.Content); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Binding_To_Ancestor_Of_Type_With_Shorthand_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'> |
|
|
|
<Border Name='border1'> |
|
|
|
<Border Name='border2'> |
|
|
|
<Button Name='button' Content='{Binding $parent[Border].Name}'/> |
|
|
|
</Border> |
|
|
|
</Border> |
|
|
|
</Window>";
|
|
|
|
var loader = new AvaloniaXamlLoader(); |
|
|
|
var window = (Window)loader.Load(xaml); |
|
|
|
var button = window.FindControl<Button>("button"); |
|
|
|
|
|
|
|
window.ApplyTemplate(); |
|
|
|
|
|
|
|
Assert.Equal("border2", button.Content); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Binding_To_Second_Ancestor_With_Shorthand_And_Type_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'> |
|
|
|
<Border Name='border1'> |
|
|
|
<Border Name='border2'> |
|
|
|
<Button Name='button' Content='{Binding $parent[Border; 1].Name}'/> |
|
|
|
</Border> |
|
|
|
</Border> |
|
|
|
</Window>";
|
|
|
|
var loader = new AvaloniaXamlLoader(); |
|
|
|
var window = (Window)loader.Load(xaml); |
|
|
|
var button = window.FindControl<Button>("button"); |
|
|
|
|
|
|
|
window.ApplyTemplate(); |
|
|
|
|
|
|
|
Assert.Equal("border1", button.Content); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Binding_To_Second_Ancestor_With_Shorthand_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'> |
|
|
|
<Border Name='border1'> |
|
|
|
<Border Name='border2'> |
|
|
|
<Button Name='button' Content='{Binding $parent[1].Name}'/> |
|
|
|
</Border> |
|
|
|
</Border> |
|
|
|
</Window>";
|
|
|
|
var loader = new AvaloniaXamlLoader(); |
|
|
|
var window = (Window)loader.Load(xaml); |
|
|
|
var button = window.FindControl<Button>("button"); |
|
|
|
|
|
|
|
window.ApplyTemplate(); |
|
|
|
|
|
|
|
Assert.Equal("border1", button.Content); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Binding_To_Ancestor_With_Namespace_Works() |
|
|
|
{ |
|
|
|
|