You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It'd be nice to have some baseline color abstraction/patterns for .NET. Something that helps create underlying data models/structures for MVVM apps that are UX agnostic.
Rather than re-implementing this type of base structure for every project, it'd be nice to have a common standard that folks can easily reference and then just extend with their own converters/extensions for interop with whatever image/graphics systems they may be using.
Also, other implementations may be hard to serialize. By having something simple and straight-forward it should be easy to serialize and use as data storage for base operations without having to rely on specific graphical requirements or OS quirks.
Things like System.Drawing.Common are Windows specific or other libraries do more with bitmaps and image manipulation. But generally with MVVM and abstracting your data model, you just want a simple object to represent a color value that can be stored in your data file. Your UI layer then takes that and uses a converter to map it to a brush or whatever else is needed to represent it on screen.
I know this isn't a fully fleshed out proposal here, but wanted to get the conversation started, as I was just about to go create a record struct for my underlying data model for file serialization in a project again...
I like the idea, but I'm going to close this since this has already been approved for .NET, hopefully .NET 10 🙂
See dotnet/runtime#48615. There's also already an open PR.
Overview
It'd be nice to have some baseline color abstraction/patterns for .NET. Something that helps create underlying data models/structures for MVVM apps that are UX agnostic.
Rather than re-implementing this type of base structure for every project, it'd be nice to have a common standard that folks can easily reference and then just extend with their own converters/extensions for interop with whatever image/graphics systems they may be using.
Also, other implementations may be hard to serialize. By having something simple and straight-forward it should be easy to serialize and use as data storage for base operations without having to rely on specific graphical requirements or OS quirks.
API breakdown
(Maybe it should be a
record struct
, I'm not sure of the pros/cons of each in this case.)It could be handy to have some helpers like a
Color.TryParse
which could try and read values like<0.5,1.0,0.25>
or#AAFF33FF
Maybe some other color space helpers/conversion methods for Hsl/Hsv? Then we would just simplify the WCT ones to provide the Windows Color type but use the implementation that's been abstracted here, see https://github.com/CommunityToolkit/Windows/tree/main/components/Helpers/src/ColorHelper
Usage example
In my .NET standard/'core' class library containing my data models:
Breaking change?
No
Alternatives
Things like
System.Drawing.Common
are Windows specific or other libraries do more with bitmaps and image manipulation. But generally with MVVM and abstracting your data model, you just want a simple object to represent a color value that can be stored in your data file. Your UI layer then takes that and uses a converter to map it to a brush or whatever else is needed to represent it on screen.https://learn.microsoft.com/dotnet/api/system.drawing?view=net-8.0#remarks
Additional context
I know this isn't a fully fleshed out proposal here, but wanted to get the conversation started, as I was just about to go create a record struct for my underlying data model for file serialization in a project again...
Not sure if it makes sense to provide named colors as well: https://learn.microsoft.com/dotnet/api/system.windows.media.colors as those are Windows only as well.
Help us help you
Yes, but only if others can assist
The text was updated successfully, but these errors were encountered: