Skip to content

[Enhancement] Provide Migration guidance for Xamarin.Forms.Color #1668

Open

Description

Summary

The Xamarin.Forms.Color struct seems to have been replaced by a combination of the Microsoft.Maui.Graphics.Color class and the Microsoft.Maui.Graphics.Colors class. Obviously these are quite different so some guidance is probably called for to deal with migration.

API Changes

If I had my druthers I think I lean toward the Xamarin.Forms approach of color as a struct rather than the MAUI approach of making it a pair of classes, mostly because I'm not sure reference semantics are appropriate and a color description doesn't take up much memory, but assuming there's a good reason to use classes instead of structs the main issues I see for people migrating code are:

  • The semantic differences between objects and classes (assignments, equality, reference counting, null references etc.)
  • Code using color literals like Color.Red would need to change to use Colors.Red (note the 's')
  • Some existing values like Color.Accent and Color.Default do not have obvious alternatives (this also shows up in XAML, where, say, Color="Accent" is used in Xamarin Forms).
  • The general move to float rather than double storage might cause some surprises but not implementing the R, G, B and A properties should at least make for compile time failures rather than run time.

If there's a blog post or something explaining why the model change to Color and Colors classes are desirable (certainly a switch to float from double to store RGBA values seems like it might perhaps save a bit of space) I'd appreciate it if someone could point me to it.

Intended Use Case

The proposed guidance would likely be needed whenever a code base with nontrivial uses of Xamarin.Forms.Color was being migrated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    area-docsConceptual docs, API docs, Samplesmigration-compatibilityXamarin.Forms to .NET MAUI Migration, Upgrade Assistant, Try-Convertt/enhancement ☀️New feature or request

    Type

    No type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions