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
32 changes: 31 additions & 1 deletion src/Controls/src/Core/CheckBox/CheckBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,37 @@ public bool IsChecked
protected internal override void ChangeVisualState()
{
if (IsEnabled && IsChecked)
VisualStateManager.GoToState(this, IsCheckedVisualState);
{
bool isCheckedStateAvailable = false;
var visualStates = VisualStateManager.GetVisualStateGroups(this);
foreach (var group in visualStates)
{
if (group.Name is not "CommonStates")
{
continue;
}

foreach (var state in group.States)
{
if (state.Name is IsCheckedVisualState)
{
isCheckedStateAvailable = true;
break;
}
}

break;
}

if (isCheckedStateAvailable)
{
VisualStateManager.GoToState(this, IsCheckedVisualState);
}
else
{
VisualStateManager.GoToState(this, VisualStateManager.CommonStates.Normal);
}
}
else
base.ChangeVisualState();
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 29 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue23608.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Maui.Controls.Sample.Issues.Issue23608"
Title="Issue23608">

<VerticalStackLayout>
<VerticalStackLayout.Resources>
<Style TargetType="CheckBox">
<Setter Property="Color" Value="violet" />
<Setter Property="VisualStateManager.VisualStateGroups">
<VisualStateGroupList>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal" />
<VisualState x:Name="Disabled">
<VisualState.Setters>
<Setter Property="Color" Value="Gray" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateGroupList>
</Setter>
</Style>
</VerticalStackLayout.Resources>
<Label Text="Enable the IsEnabled property" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" AutomationId="Label" />
<Switch AutomationId="Switch" HorizontalOptions="Center" IsToggled="{Binding IsEnabled}" />
<CheckBox IsChecked="true" IsEnabled="{Binding IsEnabled}" />
</VerticalStackLayout>
</ContentPage>
39 changes: 39 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue23608.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System.ComponentModel;
using System.Runtime.CompilerServices;

namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 23608, "The checkbox's checked state color does not update when the IsEnabled property is changed dynamically", PlatformAffected.All)]
public partial class Issue23608 : ContentPage
{
public Issue23608()
{
InitializeComponent();
BindingContext = new Issue23608ViewModel();
}
}

public class Issue23608ViewModel : INotifyPropertyChanged
{
private bool _isEnabled = false;

public bool IsEnabled
{
get => _isEnabled;
set
{
if (_isEnabled != value)
{
_isEnabled = value;
OnPropertyChanged();
}
}
}

public event PropertyChangedEventHandler PropertyChanged;

protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues
{
public class Issue23608 : _IssuesUITest
{
public Issue23608(TestDevice device) : base(device)
{
}

public override string Issue => "The checkbox's checked state color does not update when the IsEnabled property is changed dynamically";

[Test]
[Category(UITestCategories.CheckBox)]
public void UpdatedIsEnabledProperty()
{
App.WaitForElement("Label");
App.Click("Switch");
VerifyScreenshot();
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading