maui icon indicating copy to clipboard operation
maui copied to clipboard

Static Color methods not converting values e.g Color.FromRgba

Open Akinnagbe opened this issue 2 years ago • 4 comments

Description

using static Color methods does not work for other forms of colors apart from the primary colors. E.g. Color.FromRgba both in C# and using FactoryMethod in xaml does not display the color on the app

Steps to Reproduce

  1. Create a File, New .Net MAUI App

  2. Add the flowing lines of code within the VerticalStackLayout

  3. XAML:

    <Frame
               IsClippedToBounds="True"
               HasShadow="False"
               CornerRadius="10"
               Margin="20">
               <Frame.BackgroundColor>
                   <Color x:FactoryMethod="FromRgba">
                       <x:Arguments>
                           <x:Double>181</x:Double>
                           <x:Double>128</x:Double>
                           <x:Double>209</x:Double>
                           <x:Double>0.5</x:Double>
                       </x:Arguments>
                   </Color>
               </Frame.BackgroundColor>
               <VerticalStackLayout
                   Spacing="5">
                   <Entry
                       Placeholder="All holdings"/>
                   <Entry
                       Placeholder="Select account"/>
               </VerticalStackLayout>
           </Frame>
    
  4. Run the application

  5. The background color is transparent

Version with bug

7.0.408 (current)

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

Android 12

Did you find any workaround?

No

Relevant log output

No response

Akinnagbe avatar Aug 06 '22 16:08 Akinnagbe

For the overload of Color.FromRgba() that takes doubles, the ranges of every channel is 0.0...1.0. Only the int overload takes numbers in the range 0..255.

These are the supported overloads:

		public static Color FromRgba(int red, int green, int blue, int alpha); // pass 0-255 for each value
		public static Color FromRgba(float r, float g, float b, float a); // pass 0.0-1.0 for each value
		public static Color FromRgba(double r, double g, double b, double a); // pass 0.0-1.0 for each value
		public static Color FromRgba(string colorAsHex); // pass a hex string

Eilon avatar Aug 08 '22 16:08 Eilon

Thanks @Eilon. I was actually using the wrong overload. It's working now.

Akinnagbe avatar Aug 09 '22 13:08 Akinnagbe

@Eilon, Please I am getting the error below, this is affecting the UI from updating

XHR0032 The property "FactoryMethod" does not exist in the "http://schemas.microsoft.com/winfx/2009/xaml" namespace

On Hot Reload

Akinnagbe avatar Aug 10 '22 15:08 Akinnagbe

So it works the first time when you run the app, but it doesn't work later during Hot Reload?

Eilon avatar Aug 10 '22 18:08 Eilon

Yes for first time run, but No during Hot Reload

Akinnagbe avatar Aug 11 '22 04:08 Akinnagbe

@Akinnagbe can you file a new issue about the second problem? (https://github.com/dotnet/maui/issues/9232#issuecomment-1210873566)

There isn't enough info here to follow up on the XAML hot reload issue. I think we'll need at least a XAML example? All we have is the error message XHR0032 The property "FactoryMethod" does not exist in the ... namespace.

Thanks!

jonathanpeppers avatar Jan 24 '23 16:01 jonathanpeppers