Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/Controls/tests/Xaml.UnitTests/Issues/Maui16960.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:Microsoft.Maui.Controls.Xaml.UnitTests"
x:Class="Microsoft.Maui.Controls.Xaml.UnitTests.Maui16960">
<ContentPage.Resources>
<Style TargetType="Button">
<Setter Property="VisualStateManager.VisualStateGroups">
<Setter.Value>
<VisualStateGroupList>
<VisualStateGroup>
<VisualState x:Name="Normal" />
<VisualState x:Name="Pressed">
<VisualState.Setters>
<Setter Property="BackgroundColor"
Value="{AppThemeBinding Light=Yellow, Dark=Orange}" />
</VisualState.Setters>
</VisualState>
<VisualState x:Name="PointerOver">
<VisualState.Setters>
<Setter Property="BackgroundColor"
Value="Red" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateGroupList>
</Setter.Value>
</Setter>
</Style>
</ContentPage.Resources>


<Button x:Name="button"/>


</ContentPage>
62 changes: 62 additions & 0 deletions src/Controls/tests/Xaml.UnitTests/Issues/Maui16960.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using Microsoft.Maui.ApplicationModel;
using Microsoft.Maui.Controls.Core.UnitTests;
using Microsoft.Maui.Controls.Shapes;
using Microsoft.Maui.Devices;
using Microsoft.Maui.Graphics;
using Microsoft.Maui.Dispatching;


using NUnit.Framework;
using Microsoft.Maui.UnitTests;

namespace Microsoft.Maui.Controls.Xaml.UnitTests;

public partial class Maui16960
{

public Maui16960() => InitializeComponent();

public Maui16960(bool useCompiledXaml)
{
//this stub will be replaced at compile time
}

[TestFixture]
class Test
{
[SetUp]
public void Setup()
{
Application.SetCurrentApplication(new MockApplication());
DispatcherProvider.SetCurrent(new DispatcherProviderStub());
}


[TearDown] public void TearDown() => AppInfo.SetCurrent(null);

[Test]
public void VSMandAppTheme([Values(false, true)] bool useCompiledXaml)
{

Application.Current.UserAppTheme = AppTheme.Light;

var page = new Maui16960(useCompiledXaml);
Button button = page.button;
Assert.That(button.BackgroundColor, Is.Null);

VisualStateManager.GoToState(button, "PointerOver");
Assert.That(button.BackgroundColor, Is.EqualTo(Colors.Red));

VisualStateManager.GoToState(button, "Pressed");
Assert.That(button.BackgroundColor, Is.EqualTo(Colors.Yellow));

VisualStateManager.GoToState(button, "Normal");
Assert.That(button.BackgroundColor, Is.Null);

VisualStateManager.GoToState(button, "PointerOver");
Assert.That(button.BackgroundColor, Is.EqualTo(Colors.Red));


}
}
}