开发者

Create RadialGradientBrush

开发者 https://www.devze.com 2023-02-14 20:44 出处:网络
I have the color # FFECE9D8, # FF716F64 how do I create a gradient brush RadialGradientBrush br = new RadialGradientBrush ();

I have the color # FFECE9D8, # FF716F64 how do I create a gradient brush

 RadialGradientBrush br = new RadialGradientBrush ();
 br.GradientStops.Add (new GradientSto开发者_运维知识库p ("# FFECE9D8", 0));
 br.GradientStops.Add (new GradientStop ("# FF716F64", 1));

Falls bug - new GradientStop ("# FF716F64", 1) - can contain a string


When creating the gradient in code instead of XAML, you cannot use strings to specify the colors. Just use Color.FromArgb() instead.

Your example then becomes this:

RadialGradientBrush br = new RadialGradientBrush();
br.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xEC, 0xE9, 0xD8), 0)); 
br.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x71, 0x6F, 0x64), 1));


You can use the ColorConverter-class to convert a string to a color.

RadialGradientBrush br = new RadialGradientBrush ();  
 br.GradientStops.Add (new GradientStop ((Color)ColorConverter.ConvertFromString("#FFECE9D8"), 0));  
 br.GradientStops.Add (new GradientStop ((Color)ColorConverter.ConvertFromString("#FF716F64"), 1)); 


Constructor of GradientStop expects Color, not string. You can do the following:

new GradientStop(Color.FromArgb(0xFF, 0xEC, 0xE9, 0xD8), 0);
0

精彩评论

暂无评论...
验证码 换一张
取 消