|
|
|
@ -9,10 +9,13 @@ using System.Threading.Tasks; |
|
|
|
using Avalonia.Controls; |
|
|
|
using Avalonia.Controls.Presenters; |
|
|
|
using Avalonia.Controls.Templates; |
|
|
|
using Avalonia.Data; |
|
|
|
using Avalonia.Data.Converters; |
|
|
|
using Avalonia.Data.Core; |
|
|
|
using Avalonia.Input; |
|
|
|
using Avalonia.Markup.Data; |
|
|
|
using Avalonia.Markup.Xaml.MarkupExtensions; |
|
|
|
using Avalonia.Markup.Xaml.MarkupExtensions.CompiledBindings; |
|
|
|
using Avalonia.Markup.Xaml.Templates; |
|
|
|
using Avalonia.Media; |
|
|
|
using Avalonia.Metadata; |
|
|
|
@ -135,6 +138,56 @@ namespace Avalonia.Markup.Xaml.UnitTests.MarkupExtensions |
|
|
|
Assert.Equal(dataContext.ListProperty, textBlock.Items); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void ResolvesDataTypeFromBindingProperty() |
|
|
|
{ |
|
|
|
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.MarkupExtensions;assembly=Avalonia.Markup.Xaml.UnitTests'> |
|
|
|
<TextBlock Text='{CompiledBinding StringProperty, DataType=local:TestDataContext}' Name='textBlock' /> |
|
|
|
</Window>";
|
|
|
|
var window = (Window)AvaloniaRuntimeXamlLoader.Load(xaml); |
|
|
|
var textBlock = window.FindControl<TextBlock>("textBlock"); |
|
|
|
|
|
|
|
var dataContext = new TestDataContext |
|
|
|
{ |
|
|
|
StringProperty = "foobar" |
|
|
|
}; |
|
|
|
|
|
|
|
window.DataContext = dataContext; |
|
|
|
|
|
|
|
Assert.Equal(dataContext.StringProperty, textBlock.Text); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void ResolvesDataTypeFromBindingProperty_TypeExtension() |
|
|
|
{ |
|
|
|
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.MarkupExtensions;assembly=Avalonia.Markup.Xaml.UnitTests'> |
|
|
|
<TextBlock Text='{CompiledBinding StringProperty, DataType={x:Type local:TestDataContext}}' Name='textBlock' /> |
|
|
|
</Window>";
|
|
|
|
var window = (Window)AvaloniaRuntimeXamlLoader.Load(xaml); |
|
|
|
var textBlock = window.FindControl<TextBlock>("textBlock"); |
|
|
|
|
|
|
|
var dataContext = new TestDataContext |
|
|
|
{ |
|
|
|
StringProperty = "foobar" |
|
|
|
}; |
|
|
|
|
|
|
|
window.DataContext = dataContext; |
|
|
|
|
|
|
|
Assert.Equal(dataContext.StringProperty, textBlock.Text); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void ResolvesStreamTaskBindingCorrectly() |
|
|
|
@ -1479,6 +1532,43 @@ namespace Avalonia.Markup.Xaml.UnitTests.MarkupExtensions |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void ResolvesDataTypeForAssignBinding() |
|
|
|
{ |
|
|
|
using (UnitTestApplication.Start(TestServices.StyledWindow)) |
|
|
|
{ |
|
|
|
var xaml = @"
|
|
|
|
<local:AssignBindingControl xmlns='https://github.com/avaloniaui'
|
|
|
|
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'
|
|
|
|
xmlns:local='clr-namespace:Avalonia.Markup.Xaml.UnitTests.MarkupExtensions;assembly=Avalonia.Markup.Xaml.UnitTests' |
|
|
|
x:DataType='local:TestDataContext' |
|
|
|
X='{CompiledBinding StringProperty}' />";
|
|
|
|
var control = (AssignBindingControl)AvaloniaRuntimeXamlLoader.Load(xaml); |
|
|
|
var compiledPath = ((CompiledBindingExtension)control.X).Path; |
|
|
|
|
|
|
|
var node = Assert.IsType<PropertyElement>(Assert.Single(compiledPath.Elements)); |
|
|
|
Assert.Equal(typeof(string), node.Property.PropertyType); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void ResolvesDataTypeForAssignBinding_FromBindingProperty() |
|
|
|
{ |
|
|
|
using (UnitTestApplication.Start(TestServices.StyledWindow)) |
|
|
|
{ |
|
|
|
var xaml = @"
|
|
|
|
<local:AssignBindingControl xmlns='https://github.com/avaloniaui'
|
|
|
|
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'
|
|
|
|
xmlns:local='clr-namespace:Avalonia.Markup.Xaml.UnitTests.MarkupExtensions;assembly=Avalonia.Markup.Xaml.UnitTests' |
|
|
|
X='{CompiledBinding StringProperty, DataType=local:TestDataContext}' />";
|
|
|
|
var control = (AssignBindingControl)AvaloniaRuntimeXamlLoader.Load(xaml); |
|
|
|
var compiledPath = ((CompiledBindingExtension)control.X).Path; |
|
|
|
|
|
|
|
var node = Assert.IsType<PropertyElement>(Assert.Single(compiledPath.Elements)); |
|
|
|
Assert.Equal(typeof(string), node.Property.PropertyType); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void Throws(string type, Action cb) |
|
|
|
{ |
|
|
|
try |
|
|
|
@ -1656,4 +1746,9 @@ namespace Avalonia.Markup.Xaml.UnitTests.MarkupExtensions |
|
|
|
} |
|
|
|
|
|
|
|
public class CustomDataTemplateInherit : CustomDataTemplate { } |
|
|
|
|
|
|
|
public class AssignBindingControl : Control |
|
|
|
{ |
|
|
|
[AssignBinding] public IBinding X { get; set; } |
|
|
|
} |
|
|
|
} |
|
|
|
|