Question: I have problem with changing color of disabled textbox. I have already 'foreground' property for my textbox when it is enabled. But I want to set another color when it is disabled. How can I achieve this?

---

@Harry

It's nothing special

XML

```
 <TextBox x:Name="txt1" HorizontalAlignment="Left" Margin="98,185,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="160" IsEnabled="False" Background="Blue" />

 <Button x:Name="btn1" Content="Button" HorizontalAlignment="Left" Margin="98,271,0,0" VerticalAlignment="Top" Click="btn1_Click"/>

```

CS:

```
  private void btn1_Click(object sender, RoutedEventArgs e)
    {

        txt1.IsEnabled = true;

    }

```

By default txt1 is disabled and has grey color. I want change this color.

I can operate only on colors of enabled texbox. Now is set to 'blue'

Answer: 
You could work with `Behaviors`

```
public class ControlBackgroundColorBehavior : DependencyObject, IBehavior
{
    private Control _contentDialog;

    public void Detach()
    {
        _contentDialog.IsEnabledChanged -= OnIsEnabledChanged;
    }

    DependencyObject IBehavior.AssociatedObject { get; }

    public DependencyObject AssociatedObject { get; private set; }

    public void Attach(DependencyObject associatedObject)
    {
        AssociatedObject = associatedObject;
        _contentDialog = AssociatedObject as ContentDialog;
        _contentDialog.IsEnabledChanged += OnIsEnabledChanged;
    }

    public Brush DisabledForegroundColor { get; set; }

    private void OnIsEnabledChanged(object sender, DependencyPropertyChangedEventArgs e)
    {
        if (!Equals(e.NewValue, true))
        {
            _contentDialog.Foreground= DisabledForegroundColor ;
        }
        else
        {
            _contentDialog.Foreground= (Brush)Control.ForegroundProperty.GetMetadata(typeof(Control)).DefaultValue;
        }
    }
}

```

And in XAML

```
<TextBox>
    <interactivity:Interaction.Behaviors>
        <yourNamespace:ControlBackgroundColorBehavior DisabledForegroundColor ="Red" />
    </interactivity:Interaction.Behaviors>
</TextBox>

```
You need to check when button is disabled then set the colour to what you need. so something like this 

```
if(txt1.IsEnabled == true){
  //enable colour
}else{
  //set disable colour
}

```

OR 

You can also set the colour inthe form load function.

so in the form load method set the colour.

```
txt1.button1.BackColor = Color.Red; 

```

or forecolor

```
txt1.ForeColor = System.Drawing.Color.Red

```

Along these lines.