---
title: "Set background color of WPF Textbox in C# code"  
description: "Set background color of WPF Textbox in C# code"  
author: "Anonymous User"  
published: 2013-07-17  
updated: 2013-07-17  
canonical: https://www.mindstick.com/forum/1297/set-background-color-of-wpf-textbox-in-c-sharp-code  
category: "wcf"  
tags: ["wcf"]  
reading_time: 1 minute  

---

# Set background color of WPF Textbox in C# code

Hi [mindstick](https://yourviews.mindstick.com/view/84668/how-mindstick-is-used-for-marketing-purposes)!

How can I change the [background](https://www.mindstick.com/articles/65/how-to-change-background-color-of-tab-control-in-c-sharp) and foreground [colors](https://answers.mindstick.com/qa/31019/should-i-paint-my-interior-with-neutral-or-bright-colors) of a [WPF](https://www.mindstick.com/forum/304/wpf) [Textbox](https://www.mindstick.com/forum/12714/dynamic-textbox-in-gridview) programmatically in c#?

Thanks in [advance](https://www.mindstick.com/blog/33258/jee-mains-and-jee-advance-exams)

## Replies

### Reply by shreesh chandra shukla

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");


---

Original Source: https://www.mindstick.com/forum/1297/set-background-color-of-wpf-textbox-in-c-sharp-code

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
