SET BACKGROUND COLOR OF WPF TEXTBOX IN C# CODE

Ankit Singh

Total Post:341

Points:2389
Posted by  Ankit Singh
WCF 
WCF
 13906  View(s)
Ratings:
Rate this:
Hi mindstick!

How can I change the background and foreground colors of a WPF Textbox programmatically in c#?

Thanks in advance

  1. shreesh chandra shukla

    Post:105

    Points:735
    Re: Set background color of WPF Textbox in C# code

    Solution!

    If you want to set the background using a Hex Color you could do this:

    var bc = new BrushConverter();

    myTextBox.Background = (Brush)bc.ConvertFrom("#FFXXXXXX");

    OR

    you could set up a SolidColorBrush resource in xaml, and then use findResource in codebehind

    <SolidColorBrush x:Key="BrushFFXXXXXX">#FF8D8A8A</SolidColorBrush>

    myTextBox.Background = (Brush)Application.Current.MainWindow.FindResource("BrushFFXXXXXX");

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!