#1,071 – How TextBox Reacts to Gaining Keyboard Focus
May 13, 2014 1 Comment
If you have an application with several TextBox controls, you’ll notice that the TextBox that currently has focus “lights up” by drawing a light blue border around the edge of the TextBox.
The TextBox draws the blue border by setting up a trigger in its control template. You can see the body of the control template by right-clicking the TextBox in Visual Studio from the design surface and selecting Edit Template, followed by Edit a Copy.
When you do this, you’ll be asked to give the new copy a name (e.g. TextBoxStyle1). You’ll then get the full body of the template in the XAML document.
Looking at this template, you’ll see a Trigger on the IsKeyboardFocused property that sets the value of the BorderBrush on a Border element. It sets it to a static resource, which is defined earlier in the template (to a light blue color).