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.
125 lines
4.1 KiB
125 lines
4.1 KiB
// Copyright (c) The Avalonia Project. All rights reserved.
|
|
// Licensed under the MIT license. See licence.md file in the project root for full license information.
|
|
|
|
using System;
|
|
using Avalonia.Controls;
|
|
using Avalonia.Markup.Xaml.Data;
|
|
using Avalonia.Media;
|
|
using Avalonia.Styling;
|
|
using Avalonia.UnitTests;
|
|
using Xunit;
|
|
|
|
namespace Avalonia.Markup.Xaml.UnitTests.Xaml
|
|
{
|
|
public class StaticResourceTests
|
|
{
|
|
[Fact]
|
|
public void StaticResource_Style_Can_Be_Assigned_To_Property()
|
|
{
|
|
var xaml = @"
|
|
<UserControl xmlns='https://github.com/avaloniaui'
|
|
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
|
|
<UserControl.Resources>
|
|
<SolidColorBrush x:Key='brush'>#ff506070</SolidColorBrush>
|
|
</UserControl.Resources>
|
|
|
|
<Border Name='border' Background='{StaticResource brush}'/>
|
|
</UserControl>";
|
|
|
|
var loader = new AvaloniaXamlLoader();
|
|
var userControl = (UserControl)loader.Load(xaml);
|
|
var border = userControl.FindControl<Border>("border");
|
|
|
|
var brush = (SolidColorBrush)border.Background;
|
|
Assert.Equal(0xff506070, brush.Color.ToUint32());
|
|
}
|
|
|
|
[Fact]
|
|
public void StaticResource_From_Style_Can_Be_Assigned_To_Property()
|
|
{
|
|
var xaml = @"
|
|
<UserControl xmlns='https://github.com/avaloniaui'
|
|
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
|
|
<UserControl.Styles>
|
|
<Style>
|
|
<Style.Resources>
|
|
<SolidColorBrush x:Key='brush'>#ff506070</SolidColorBrush>
|
|
</Style.Resources>
|
|
</Style>
|
|
</UserControl.Styles>
|
|
|
|
<Border Name='border' Background='{StaticResource brush}'/>
|
|
</UserControl>";
|
|
|
|
var loader = new AvaloniaXamlLoader();
|
|
var userControl = (UserControl)loader.Load(xaml);
|
|
var border = userControl.FindControl<Border>("border");
|
|
|
|
var brush = (SolidColorBrush)border.Background;
|
|
Assert.Equal(0xff506070, brush.Color.ToUint32());
|
|
}
|
|
|
|
[Fact]
|
|
public void StaticResource_Can_Be_Assigned_To_Setter()
|
|
{
|
|
using (StyledWindowNoTheme())
|
|
{
|
|
var xaml = @"
|
|
<Window xmlns='https://github.com/avaloniaui'
|
|
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
|
|
<Window.Resources>
|
|
<SolidColorBrush x:Key='brush'>#ff506070</SolidColorBrush>
|
|
</Window.Resources>
|
|
<Window.Styles>
|
|
<Style Selector='Button'>
|
|
<Setter Property='Background' Value='{StaticResource brush}'/>
|
|
</Style>
|
|
</Window.Styles>
|
|
<Button Name='button'/>
|
|
</Window>";
|
|
|
|
var loader = new AvaloniaXamlLoader();
|
|
var window = (Window)loader.Load(xaml);
|
|
var button = window.FindControl<Button>("button");
|
|
var brush = (SolidColorBrush)button.Background;
|
|
|
|
Assert.Equal(0xff506070, brush.Color.ToUint32());
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void StaticResource_From_Style_Can_Be_Assigned_To_Setter()
|
|
{
|
|
using (StyledWindowNoTheme())
|
|
{
|
|
var xaml = @"
|
|
<Window xmlns='https://github.com/avaloniaui'
|
|
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
|
|
<Window.Styles>
|
|
<Style>
|
|
<Style.Resources>
|
|
<SolidColorBrush x:Key='brush'>#ff506070</SolidColorBrush>
|
|
</Style.Resources>
|
|
</Style>
|
|
<Style Selector='Button'>
|
|
<Setter Property='Background' Value='{StaticResource brush}'/>
|
|
</Style>
|
|
</Window.Styles>
|
|
<Button Name='button'/>
|
|
</Window>";
|
|
|
|
var loader = new AvaloniaXamlLoader();
|
|
var window = (Window)loader.Load(xaml);
|
|
var button = window.FindControl<Button>("button");
|
|
var brush = (SolidColorBrush)button.Background;
|
|
|
|
Assert.Equal(0xff506070, brush.Color.ToUint32());
|
|
}
|
|
}
|
|
|
|
private IDisposable StyledWindowNoTheme()
|
|
{
|
|
return UnitTestApplication.Start(TestServices.StyledWindow.With(theme: () => new Styles()));
|
|
}
|
|
}
|
|
}
|
|
|