convert from Color to brush



  • 6 Answer(s)

    The solution is for Color to Brush

    To make a new brush..

    SolidColorBrush brush = new SolidColorBrush( myColor );
    

    Any more, if it need it in XAML, then make a custom value converter and use if it required.

    Answered on December 20, 2018.
    Add Comment

    Try this solution:

    Brush brush = new SolidColorBrush(color);
    

    The another way about:

    if (brush is SolidColorBrush)
    {
        Color color = (brush as SolidColorBrush).Color;
    }
    

    Either look  like.

    Mark that  not all brushes are colors but  should turn all colors into a SolidColor Brush.

    Answered on December 20, 2018.
    Add Comment

    Here is the solution:

    SolidColorBrush brush = new SolidColorBrush( Color.FromArgb(255,255,139,0) )
    
    
    Answered on December 20, 2018.
    Add Comment

    Use BrushConverter from the System.ComponentModel namespace:

    BrushConverter conv = new BrushConverter();

    You can use a color name:

    SolidColorBrush brush = conv.ConvertFromString(“Red”as SolidColorBrush;

    You can also use an RGB value:

     

    SolidColorBrush brush = conv.ConvertFromString(“#0000FF”as SolidColorBrush;

     

    I suspect you can use anything you can use in XAML.

    Answered on January 15, 2019.
    Add Comment

    Color to Brush….

    you can’t convert it, you have to make a new brush….

    SolidColorBrush brush = new SolidColorBrush( myColor );

    now, if you need it in XAML, you COULD make a custom value converter and use that in a binding

    Answered on January 15, 2019.
    Add Comment
    System.Drawing.Color MyColor = System.Drawing.Color.Red;
    System.Windows.Media.Color = ConvertColorType(MyColor);
    
    System.Windows.Media.Color ConvertColorType(System.Drawing.Color color)
    {
      byte AVal = color.A;
      byte RVal = color.R;
      byte GVal = color.G;
      byte BVal = color.B;
    
      return System.Media.Color.FromArgb(AVal, RVal, GVal, BVal);
    }

     

    Answered on January 28, 2019.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.