Open
Description
Is your feature request related to a problem? Please describe.
Currently, Avalonia Color.Parse supports multiple color formats as an input. But ToString()
cannot be configured to reliably output any of them.
Minimum required:
- Default - well-known const or fallback to XAML hex
- Well formatted XAML hex format (with forced leading alpha) -
#aarrggbb
- Short XAML hex format (with optional leading alpha) -
#aarrggbb
,#rrggbb
,#argb
,#rgb
Optional for CSS compat:
- Well formatted HTML hex format (with forced trailing alpha) -
#rrggbbaa
- Short HTML hex format (with optional trailing alpha) -
#rrggbbaa
,#rrggbb
,#rgba
,#rgb
- Well formatted absolute CSS rgb -
rgb(31, 120, 50, 255)
- Well formatted relative CSS rgb -
rgb(50%, 50%, 50%, 50%)
Note: there is way more css formats that can be supported, but we can't/don't need to support all of them.
Describe the solution you'd like
This proposal suggests implementing standard IFormattable.ToString(string? format, IFormatProvider?)
.
Similarly to well-known integer/float/date/time formats, there should be a set of formats for colors. IFormatProvider
won't be used.
Describe alternatives you've considered
No response
Additional context
Color.ParseExact
would be a reasonable proposal on its own. But let's keep it out of the scope.