How to set Brush from RGB or hex

2.3k Views Asked by At

Hey I want to set color of BorderBrush in .xaml.cs file and don't want to use colours like Red or Green and want to use whole palette from HEX or RGB. I don't know how to covert it. Maybe you know how to solve this problem.

    private void TxbName_MouseEnter(object sender, MouseEventArgs e)
    {
        txbName.BorderBrush = Brushes.Green;
        txblImie.Foreground = Brushes.Red;
    }
1

There are 1 best solutions below

1
bolkay On

You can use the ConvertFrom method from BrushConverter.

var converter=new BrushConverter();
txblImie.Foreground = (Brush)converter.ConvertFrom("#ff0000");