Color Visualization and New Creation

Asked

Viewed 79 times

2

I need to make use of the class Colors defined in namespace Windows.UI.

There are many colors available and I need to find a way or place to see a preview of these colors, because only by name it is difficult to know the result.

It is possible to create new colors either RGB-based or hexadecimal-based (HTML)?

2 answers

3

See if the color example shown in that documentation help you.

There are some Color Picker software that do by name (I imagine these are universal names). An online that does this.

The ideal would be to make a code that generates all of them, including the content you want. You can do this easily using reflection by reading all members of the class and using the colors in whatever you want. Actually someone’s already done it with another class of colors and should be very easy to adapt to your need. There are examples too.

It is possible to use any of the RGB palette, ie about 16 million colors, normally used hexadecimal (ex.: #C010FF). The class is a facilitator with widely used colors.

Note that where a color waits for a structure https://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.color.aspx which is composed of 3 bytes, one for each basic color (there is a fourth alpha layer, but that does not matter in this context). So what you put there is a number that you can put in hexadecimal or decimal. The colors of this class are just names for predefined values, you do not put a name there but a number, the name is just to help you. It is not difficult to emphasize that variables are just names for a position in memory, which has values. There is nothing special about this.

What is special about XAML is that it identifies itself whether it is using a name or value. This is done internally through type converters, but you don’t even need to know it to use.

  • And how would I use a color that is not in the class? In my case I am changing the color of the title bar and window buttons with var titleBar = ApplicationView.GetForCurrentView ( ).TitleBar; and titleBar.BackgroundColor = Colors.DimGray. In my case I want a darker gray than those available in class.

  • @Matheussaraiva using hexadecimal that defines a color, as I said in the answer. Where it accepts a color it accepts the structure https://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.color.aspx. What it puts there is always a color code with 3 bytes, one for each color. The class Colors only has some numbers ready for use in specific names.

  • Actually my question is how I should insert hexadecimal. That is, as String or in some method that receives an Hex string and converts to one Color. I used the @rubStackOverflow response, and discovered the method Color.FromArgb(int a, int r, int g, int b) . Working well now, but if there is a way to pass an Hex, I find more practical.

  • @Matheussaraiva you saw the documentation that I Linkei? There are examples of use. If it is XAML you can use direct hexadecimal as string, Otherwise you will have to fill each property (each color) of the structure with a number. You can do using hexadecimal or decimal notation if you prefer.

  • So I searched there is no way to modify the colors of the title bar and close, maximize and minimize buttons of the window via XAML. I’m doing this via C# code on App.xaml.cs. I researched some more and it seems that there is nothing ready, where the solution is to create a method that does the conversion as in http://stackoverflow.com/questions/28782399/converting-a-string-hex-to-color-in-windows-phone-runtime-c-sharp

  • Just correcting. The parameters of FromArgb() are of the type byte and not int

  • 1

    @Matheussaraiva is possible.

  • On second thought, you’re right. App.xaml.cs is nothing more than the code-Behind of the App.xaml.

Show 3 more comments

2

An alternative (paid) Resharper (obviously using this tool only to view and create new colors is not feasible)

MeuBotao.Background = new SolidColorBrush(Color.FromArgb(255,0,0,255));

inserir a descrição da imagem aqui


inserir a descrição da imagem aqui

Browser other questions tagged

You are not signed in. Login or sign up in order to post.