csharpc-sharpdotnetxamlavaloniauicross-platformcross-platform-xamlavaloniaguimulti-platformuser-interfacedotnetcore
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.5 KiB
47 lines
1.5 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using Avalonia.Controls;
|
|
using Avalonia.Markup.Data;
|
|
using Avalonia.UnitTests;
|
|
using Xunit;
|
|
|
|
namespace Avalonia.Markup.Xaml.UnitTests.MarkupExtensions
|
|
{
|
|
public class CompiledBindingExtensionTests
|
|
{
|
|
[Fact]
|
|
public void ResolvesClrPropertyBasedOnDataContextType()
|
|
{
|
|
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:DataContextType='{x:Type local:TestDataContext}'>
|
|
<TextBlock Text='{CompiledBinding StringProperty}' Name='textBlock' />
|
|
</Window>";
|
|
var loader = new AvaloniaXamlLoader();
|
|
var window = (Window)loader.Load(xaml);
|
|
var textBlock = window.FindControl<TextBlock>("textBlock");
|
|
|
|
DelayedBinding.ApplyBindings(textBlock);
|
|
|
|
var dataContext = new TestDataContext
|
|
{
|
|
StringProperty = "foobar"
|
|
};
|
|
|
|
window.DataContext = dataContext;
|
|
|
|
Assert.Equal(dataContext.StringProperty, textBlock.Text);
|
|
}
|
|
}
|
|
}
|
|
|
|
public class TestDataContext
|
|
{
|
|
public string StringProperty { get; set; }
|
|
}
|
|
}
|
|
|