Change custom color for Rectangle.Fill or Grid.Background

吃可爱长大的小学妹 提交于 2019-12-20 03:17:22

问题


i can change custom color Rectangle with something like : "#A125AA" in xaml.

But i don't know where to find code change custom color i have

i just know code for color arealy have

this.gridgcolor.Background = new SolidColorBrush(Colors.Blue);

回答1:


you can set the color through RGB. This isn't done in hex like you're doing in your xaml.

Color color = new Color() { R = 255, G = 255, B = 255 };
Brush brush= new SolidColorBrush(color);

the hex values you have in your example #A125AA are also RGB R = A1, G = 25, B = AA

You could convert these values with a helper method so you can add them to your Color object.

If you want to use the names, here is also a list of a lot of RGB codes matched to their names




回答2:


You can use the hexadecimal number directly in your XAML, as the following shows :-

        <Grid x:Name="ContentPanel"
          Grid.Row="1"
          Margin="12,0,12,0"
          Background="#A125AA"></Grid>


来源:https://stackoverflow.com/questions/10532056/change-custom-color-for-rectangle-fill-or-grid-background

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!