Skip to content

Migrating Color and VisualStateManager #6454

Open
@david-maw

Description

@david-maw

Description

The behavior of Color and VisualStateManager in MAUI is sufficiently different that migration is challenging. I've commented on some aspects of this before (see issue #1668) but the combination of several design decisions makes migration especially painful.

The attached example, a simple single page application with a label and 3 entry fields shows some of the issues.

Steps to Reproduce

  1. Unzip the Xamarin solution from Simple-VisualStateManager-Xamarin.zip
  2. Compile and run it on Android, you should see what's below. Click on the three entry lines in succession to see the first and second highlighted in yellow when they are selected. Completely independently, the label should change color every 3 seconds):
    Simple-VisualStateManager-Xamarin-Android
  3. Unzip the MAUI project from: Simple-VisualStateManager-MAUI.zip
  4. Compile and run it under Android then click on the three entry lines in succession and you should see this:
    Simple-VisualStateManager-MAUI-Android
  5. Repeat under Windows and you should see this:
    Simple-VisualStateManager-MAUI-Windows

Comparing the code in MainPage.xaml.cs between Xamarin and MAUI the significant changes are:

The other issues are with the XAML and especially with the VisualStateManager implementations. The first VisualStateManager sets an Entry background color in a Focused state and specifies nothing for a Normal state which means switching back to a Normal state sets BackGroundColor to null. Taken in conjunction with pull request #1485 this means the switch back is ignored and the Selected background color persists. Again for new code there's a fairly easy workaround, for existing code it's trickier.

Finally, there are the other functional differences in the MAUI version of the sample:

  1. On Android the second entry field is not underlined.
  2. On Android the placeholder text begins slightly to the left of where it should on the second entry line.
  3. On Android in Xamarin forms the selected Entry gets a red underline, on MAUI it does not.
  4. On Windows the VisualStateManager specifications seem to have no effect at all.

Version with bug

Release Candidate 1 (current)

Last version that worked well

Unknown/Other

Affected platforms

Android, Windows, I was not able test on other platforms

Affected platform versions

Android 11, Windows 10

Did you find any workaround?

Sometimes. See above (and the code)

Relevant log output

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-xamlXAML, CSS, Triggers, Behaviorsplatform/androidplatform/windowss/triagedIssue has been revieweds/verifiedVerified / Reproducible Issue ready for Engineering Triaget/bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions