5

Semi-Transparent background of the Textbox is needed, and the text content should be shown as normal.

Style or Brush which can store in the Resource dictionary is good.

NOTE:

  1. My textBox is wrapped within a ContentControl.

  2. This similar question does not help. TextBox with a Transparent Background .

Community
  • 1
  • 1
dongx
  • 1,750
  • 4
  • 17
  • 37

2 Answers2

19

In XAML you can set Background property to Transparent:

<TextBox Background="Transparent" />

In code-behind you can use following code:

TextBox tb = new TextBox 
{
    Width = 100,
    Background = Brushes.Transparent
};

If you want to set background to transparent to all TextBox you can use following style:

<Style TargetType="TextBox">
    <Setter Property="Background" Value="Transparent" />
</Style>
kmatyaszek
  • 19,016
  • 9
  • 60
  • 65
1

If you want to set a semi-transparent background in code-behind you can do this

use a dependency prop on a class that inherits from TextBox

public static readonly DependencyProperty BgColourProperty =
  DependencyProperty.Register("BgColour", typeof(SolidColorBrush), typeof(myTextBox), null);

public SolidColorBrush BgColour
    {
        get { return (SolidColorBrush)GetValue(BgColourProperty); }
        set { SetValue(BgColourProperty, value); }
    }

then set whatever colour you wish using Color.FromArgb() where 1st argument is Alpha component

myTextBox.BgColour = new SolidColorBrush(Color.FromArgb(120,240, 17, 17));
Constanta
  • 399
  • 4
  • 15