How would I change the background color of a TextBox Control in the Default Style Xaml to be a different color when the control is either Disabled or ReadOnly ?
A:
You can achieve this with triggers in the style:
<TextBox>
<TextBox.Style>
<Style TargetType="TextBox">
<Style.Triggers>
<Trigger Property="IsReadOnly" Value="True">
<Setter Property="Background" Value="Green" />
</Trigger>
<Trigger Property="IsEnabled" Value="True">
<Setter Property="Background" Value="Red" />
</Trigger>
</Style.Triggers>
</Style>
</TextBox.Style>
</TextBox>
naacal
2010-09-15 19:38:10
I get an error, "The attachable property Triggers was not found in Style"
gmcalab
2010-09-15 19:45:29
@gmcalab Style.Triggers are not supported in Silverlight; this is WPF-only.
Jay
2010-09-16 02:39:49
@Jay, yes I know.
gmcalab
2010-09-16 03:54:04
A:
Im not at a PC at the moment (just mobile) but I think you can edit the template of your control and there are some Visual States for your some controls that define things like disabled states, mouse overs, etc... which you should be able to redefine?
Mark
2010-09-16 11:42:34
A:
The way I accomplished this was to create a Converter
for the control.
When the control is bound to an object it detects if the control is Enabled
from this object that it is bound to. Based upon this it sets the background color for the Textbox
accordingly.
gmcalab
2010-09-24 20:34:33