string colorString = "#FF0000"; // red BrushConverter converter = new BrushConverter(); Brush brush = converter.ConvertFromString(colorString) as Brush;
string gradientString = "LinearGradientBrush(#FF0000, #FFFF00)"; // red to yellow gradient BrushConverter converter = new BrushConverter(); Brush brush = converter.ConvertFromString(gradientString) as Brush;This example converts the string representation of a gradient from red to yellow into a Brush object using the BrushConverter class. The resulting Brush object can then be used to fill shapes with the gradient. The BrushConverter class is found in the System.Windows.Media namespace, which is part of the WindowsBase.dll library.