As far as I understand I should be using Style triggers to update the TextBox\'s border colour when it is focused. However no matter what I do it always turns to the system
Try set for BorderThickness
value more than 1
(by default):
Tested on Windows Seven.
Edit: why is this happening?
I looked in the default style for TextBox
in Blend under Windows 7, here it is ControlTemplate:
Here there is two parameters:
RenderMouseOver="{TemplateBinding IsMouseOver}"
RenderFocused="{TemplateBinding IsKeyboardFocusWithin}"
They are responsible for blue gradient Border when states Focus
and MouseOver
and probably there stands a condition on BorderThickness
and BorderBrush
. If they remove / reset
the blue gradient Border will disappear and will not need to set values for BorderThickness
greater than 1.
In ILSpy
I found ChangeVisualState(bool)
method in TextBoxBase class, here it is:
internal override void ChangeVisualState(bool useTransitions)
{
if (!base.IsEnabled)
{
VisualStateManager.GoToState(this, "Disabled", useTransitions);
}
else
{
if (this.IsReadOnly)
{
VisualStateManager.GoToState(this, "ReadOnly", useTransitions);
}
else
{
if (base.IsMouseOver)
{
VisualStateManager.GoToState(this, "MouseOver", useTransitions);
}
else
{
VisualStateManager.GoToState(this, "Normal", useTransitions);
}
}
}
if (base.IsKeyboardFocused)
{
VisualStateManager.GoToState(this, "Focused", useTransitions);
}
else
{
VisualStateManager.GoToState(this, "Unfocused", useTransitions);
}
base.ChangeVisualState(useTransitions);
}
It turns out that these visual states implemented "systematically" and in Styles not present.