|
|
|
@ -938,6 +938,110 @@ namespace Avalonia.Markup.Xaml.UnitTests.MarkupExtensions |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void SupportsEmptyPath() |
|
|
|
{ |
|
|
|
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' |
|
|
|
x:DataType='local:TestDataContext'> |
|
|
|
<TextBlock Text='{CompiledBinding}' 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(typeof(TestDataContext).FullName, textBlock.Text); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void SupportsEmptyPathWithStringFormat() |
|
|
|
{ |
|
|
|
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' |
|
|
|
x:DataType='local:TestDataContext'> |
|
|
|
<TextBlock Text='{CompiledBinding StringFormat=bar-\{0\}}' 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("bar-" + typeof(TestDataContext).FullName, textBlock.Text); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void SupportsDotPath() |
|
|
|
{ |
|
|
|
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' |
|
|
|
x:DataType='local:TestDataContext'> |
|
|
|
<TextBlock Text='{CompiledBinding .}' 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(typeof(TestDataContext).FullName, textBlock.Text); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void SupportsExplicitDotPathWithStringFormat() |
|
|
|
{ |
|
|
|
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' |
|
|
|
x:DataType='local:TestDataContext'> |
|
|
|
<TextBlock Text='{CompiledBinding Path=., StringFormat=bar-\{0\}}' 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("bar-" + typeof(TestDataContext).FullName, textBlock.Text); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void Throws(string type, Action cb) |
|
|
|
{ |
|
|
|
try |
|
|
|
|