using Avalonia.Controls;
using Avalonia.Controls.Presenters;
using Avalonia.Controls.Primitives;
using Avalonia.Data;
using Avalonia.Markup.Xaml.Templates;
using Avalonia.Media;
using Avalonia.Styling;
using Avalonia.UnitTests;
using Avalonia.VisualTree;
using Xunit;
namespace Avalonia.Markup.Xaml.UnitTests.Xaml
{
public class ControlThemeTests : XamlTestBase
{
[Fact]
public void ControlTheme_Can_Be_StaticResource()
{
using (UnitTestApplication.Start(TestServices.StyledWindow))
{
var xaml = $@"
{ControlThemeXaml}
";
var window = (Window)AvaloniaRuntimeXamlLoader.Load(xaml);
var button = Assert.IsType(window.Content);
window.Show();
Assert.NotNull(button.Template);
var child = Assert.Single(button.GetVisualChildren());
var border = Assert.IsType(child);
Assert.Equal(Brushes.Red, border.Background);
}
}
[Fact]
public void ControlTheme_Can_Be_DynamicResource()
{
using (UnitTestApplication.Start(TestServices.StyledWindow))
{
var xaml = $@"
{ControlThemeXaml}
";
var window = (Window)AvaloniaRuntimeXamlLoader.Load(xaml);
var button = Assert.IsType(window.Content);
window.Show();
Assert.NotNull(button.Template);
var child = Assert.Single(button.GetVisualChildren());
var border = Assert.IsType(child);
Assert.Equal(Brushes.Red, border.Background);
}
}
[Fact]
public void ControlTheme_Can_Be_Set_In_Style()
{
using (UnitTestApplication.Start(TestServices.StyledWindow))
{
var xaml = $@"
{ControlThemeXaml}
";
var window = (Window)AvaloniaRuntimeXamlLoader.Load(xaml);
var button = Assert.IsType(window.Content);
window.Show();
Assert.NotNull(button.Template);
var child = Assert.Single(button.GetVisualChildren());
var border = Assert.IsType(child);
Assert.Equal(Brushes.Red, border.Background);
}
}
[Fact]
public void Correctly_Resolve_TemplateBinding_In_Nested_Style()
{
using (UnitTestApplication.Start(TestServices.StyledWindow))
{
var xaml = $@"
";
var theme = (ControlTheme)AvaloniaRuntimeXamlLoader.Load(xaml);
var style = Assert.IsType
";
}
}