|
|
|
@ -1,8 +1,12 @@ |
|
|
|
using Avalonia.Controls; |
|
|
|
using System.Linq; |
|
|
|
using Avalonia.Controls; |
|
|
|
using Avalonia.Controls.Presenters; |
|
|
|
using Avalonia.Controls.Primitives; |
|
|
|
using Avalonia.Markup.Data; |
|
|
|
using Avalonia.Markup.Xaml.MarkupExtensions; |
|
|
|
using Avalonia.Media; |
|
|
|
using Avalonia.Styling; |
|
|
|
using Avalonia.UnitTests; |
|
|
|
using Moq; |
|
|
|
using Xunit; |
|
|
|
|
|
|
|
@ -444,4 +448,71 @@ public class ThemeDictionariesTests : XamlTestBase |
|
|
|
|
|
|
|
Assert.Equal(Colors.Black, ((ISolidColorBrush)border.Background)!.Color); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Theme_Switch_Works_In_Nested_Scope() |
|
|
|
{ |
|
|
|
using (UnitTestApplication.Start(TestServices.StyledWindow)) |
|
|
|
{ |
|
|
|
var window = (Window)AvaloniaRuntimeXamlLoader.Load(@"
|
|
|
|
<Window xmlns='https://github.com/avaloniaui'
|
|
|
|
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'
|
|
|
|
RequestedThemeVariant='Dark'> |
|
|
|
<ThemeVariantScope Name='Scope'> |
|
|
|
<TextBlock Name='Text' /> |
|
|
|
</ThemeVariantScope> |
|
|
|
</Window>");
|
|
|
|
window.ApplyTemplate(); |
|
|
|
|
|
|
|
var scope = window.FindControl<ThemeVariantScope>("Scope")!; |
|
|
|
var text = window.FindControl<TextBlock>("Text")!; |
|
|
|
|
|
|
|
Assert.Equal(ThemeVariant.Dark, text.ActualThemeVariant); |
|
|
|
Assert.Equal(Color.Parse("#dedede"), ((ISolidColorBrush)text.Foreground!).Color); |
|
|
|
|
|
|
|
scope.RequestedThemeVariant = ThemeVariant.Light; |
|
|
|
Assert.Equal(ThemeVariant.Light, text.ActualThemeVariant); |
|
|
|
Assert.Equal(Colors.Black, ((ISolidColorBrush)text.Foreground!).Color); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Theme_Switch_Works_In_With_Popup() |
|
|
|
{ |
|
|
|
using (UnitTestApplication.Start(TestServices.StyledWindow)) |
|
|
|
{ |
|
|
|
using (UnitTestApplication.Start(TestServices.StyledWindow)) |
|
|
|
{ |
|
|
|
var window = (Window)AvaloniaRuntimeXamlLoader.Load(@"
|
|
|
|
<Window xmlns='https://github.com/avaloniaui'
|
|
|
|
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
|
|
|
|
<ThemeVariantScope Name='Scope' RequestedThemeVariant='Dark'> |
|
|
|
<Popup Name='Popup'> |
|
|
|
<Border Width='100' Height='100' |
|
|
|
Background='{DynamicResource ThemeBackgroundBrush}'> |
|
|
|
</Border> |
|
|
|
</Popup> |
|
|
|
</ThemeVariantScope> |
|
|
|
</Window>");
|
|
|
|
window.Show(); |
|
|
|
|
|
|
|
var scope = window.FindControl<ThemeVariantScope>("Scope")!; |
|
|
|
var popup = window.FindControl<Popup>("Popup")!; |
|
|
|
|
|
|
|
popup.IsOpen = true; |
|
|
|
|
|
|
|
var border = (Border)popup.Child!; |
|
|
|
|
|
|
|
Assert.Equal(ThemeVariant.Dark, popup.ActualThemeVariant); |
|
|
|
Assert.Equal(ThemeVariant.Dark, border.ActualThemeVariant); |
|
|
|
Assert.Equal(Color.Parse("#282828"), ((ISolidColorBrush)border.Background!).Color); |
|
|
|
|
|
|
|
scope.RequestedThemeVariant = ThemeVariant.Light; |
|
|
|
|
|
|
|
Assert.Equal(ThemeVariant.Light, popup.ActualThemeVariant); |
|
|
|
Assert.Equal(ThemeVariant.Light, border.ActualThemeVariant); |
|
|
|
Assert.Equal(Colors.White, ((ISolidColorBrush)border.Background!).Color); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|