Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.
This repository was archived by the owner on May 1, 2024. It is now read-only.

[Bug] Checked CheckBox does not update VisualState properly #9106

Open
@nicktiberi

Description

@nicktiberi

Description

Using a CheckBox with Normal and Disabled VisualState, when the CheckBox is checked and IsEnabled is False, the CheckBox does not update to use the Normal VisualState when IsEnabled is updated to True.

If the CheckBox is unchecked, the VisualState transitions as expected (the color of the checkbox updates as as IsEnabled is toggled on and off.

Steps to Reproduce

  1. Create a CheckBox with Normal and Disabled VisualState, and set a different Color on each state.
  2. Check the CheckBox and set the IsEnabled property to False. The Color should correspond to the value set for the Disabled state.
  3. Set the IsEnabled property to True. The Color of the CheckBox will not update unless you uncheck and recheck the CheckBox.

Expected Behavior

If the CheckBox is checked and IsEnabled is changed from False to True, the CheckBox should use the Normal VisualState instead of the Disabled VisualState.

Actual Behavior

If the CheckBox is checked and IsEnabled is changed from False to True, the CheckBox still uses the Disabled VisualState.

Basic Information

  • Version with issue: Xamarin.Forms 4.4
  • IDE: Visual Studio Mac
  • Platform Target Frameworks:
    • iOS
    • Android

Video Demo

https://www.youtube.com/watch?v=36iF9-S6wmM&feature=youtu.be

Reproduction Link

I've attached a small example project demonstrating the issue. The relevant files are TestPage.xaml and TestViewModel.cs.

Test Project Download

XAML

<?xml version="1.0" encoding="utf-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:d="http://xamarin.com/schemas/2014/forms/design"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             mc:Ignorable="d"
             x:Class="test.Views.TestPage"
             xmlns:vm="clr-namespace:test.ViewModels">
    <ContentPage.BindingContext>
        <vm:TestViewModel />
    </ContentPage.BindingContext>
    <StackLayout>
        <Label Text="{Binding CheckboxEnabledText}" />
        <Switch IsToggled="{Binding IsCheckboxEnabled}" />

        <CheckBox IsEnabled="{Binding IsCheckboxEnabled}">
            <VisualStateManager.VisualStateGroups>
                <VisualStateGroup x:Name="CommonStates">
                    <VisualState x:Name="Normal">
                        <VisualState.Setters>
                            <Setter Property="Color" Value="Green" />
                        </VisualState.Setters>
                    </VisualState>

                    <VisualState x:Name="Focused" />

                    <VisualState x:Name="Disabled">
                        <VisualState.Setters>
                            <Setter Property="Color" Value="Gray" />
                        </VisualState.Setters>
                    </VisualState>
                </VisualStateGroup>
            </VisualStateManager.VisualStateGroups>
        </CheckBox>
    </StackLayout>
</ContentPage>

ViewModel

using System.Windows.Input;

namespace test.ViewModels
{
    public class TestViewModel : BaseViewModel
    {
        private bool isCheckboxEnabled;
        public bool IsCheckboxEnabled
        {
            get => isCheckboxEnabled;

            set
            {
                isCheckboxEnabled = value;
                OnPropertyChanged(nameof(IsCheckboxEnabled));
                OnPropertyChanged(nameof(CheckboxEnabledText));
            }
        }

        public string CheckboxEnabledText
        {
            get
            {
                if (IsCheckboxEnabled)
                {
                    return "checkbox enabled (green)";
                }
                else
                {
                    return "checkbox disabled (gray)";
                }
            }
        }

        public ICommand OpenWebCommand { get; }
    }
}
``

Metadata

Metadata

Assignees

No one assigned

    Labels

    Coree/3 🕒3in-progressThis issue has an associated pull request that may resolve it!t/bug 🐛up-for-grabsWe welcome community contributions to any issue, but these might be a good place to start!

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions