0
    <Style TargetType="{x:Type TextBox}">
    <Setter Property="SnapsToDevicePixels" Value="True" />
    <Setter Property="OverridesDefaultStyle" Value="True" />
    <Setter Property="KeyboardNavigation.TabNavigation" Value="None" />
    <Setter Property="FocusVisualStyle" Value="{x:Null}" />
    <Setter Property="MinWidth" Value="120" />
    <Setter Property="MinHeight" Value="25" />
    <Setter Property="AllowDrop" Value="true" />
    <Setter Property="FontSize" Value="16"/>
    <Setter Property="FontFamily" Value="Arial"/>
    <Setter Property="VerticalContentAlignment" Value="Center"/>
    <Setter Property="VerticalAlignment" Value="Bottom"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type TextBoxBase}">
                <Border Name="Border" CornerRadius="6" Padding="2" BorderBrush="Black" BorderThickness="2,1">
                    <ScrollViewer Margin="0" x:Name="PART_ContentHost" />
                </Border>
                <ControlTemplate.Triggers>




                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

The code above is currently what I have for my text box. What do I put in the ControlTemplate.Trigger in order for my border to change from its color black to Blue or increase the Border size when it is clicked on. I have tried a few things without any luck. This includes style.Triggers and events. Please post the code that goes between the ControlTemplate.Trigger.

Thomas Bouman
  • 608
  • 4
  • 17
netgen
  • 35
  • 9
  • You tried a few things, like what? – Chris W. Jun 04 '15 at 18:39
  • I mentioned it above. Like using style.trigger and some kind of event thing. I basically tried the things in http://stackoverflow.com/questions/26769314/style-triggers-vs-controltemplate-triggers and https://msdn.microsoft.com/en-us/library/ms750947(v=vs.110).aspx and https://msdn.microsoft.com/en-us/library/system.windows.controls.controltemplate.triggers%28v=vs.110%29.aspx but could not get anything to do it. – netgen Jun 04 '15 at 19:01

1 Answers1

0

This assumes you want to border to be changed when you have it focused, since clicking a textbox focuses it. There is no OnClick property available, this changes the border of a textbox once you have it focused.

<Trigger Property="IsKeyboardFocusWithin"
         Value="True">
    <Setter Property="BorderBrush"
            TargetName="Border"
            Value="Blue"/>
</Trigger>

Edit:

To simply remove focus, add the following MouseDown event handler to your Window or Page:

MouseDown="Window_MouseDown"

And in your code behind:

private void Window_MouseDown(object sender, MouseButtonEventArgs e)
    {
        Keyboard.ClearFocus();
    }

This will correctly remove focus from your TextBox and thus unset the trigger to have a black bar again.

Thomas Bouman
  • 608
  • 4
  • 17
  • Thanks, that worked. How do I get it to return to normal if I click out? – netgen Jun 05 '15 at 14:01
  • Well, as soon as your keyboard focus is gone it should return the normal color. Does that work if you have another textbox where you click into after? – Thomas Bouman Jun 05 '15 at 14:02
  • yes, it does. I figured it would but I was thinking that I wanted it to not show if they clicked somewhere on the screen. I guess thinking about it it does not really matter for this moment. – netgen Jun 05 '15 at 14:19
  • You should be able to get that behavior working with these answers(http://stackoverflow.com/questions/6489032/wpf-remove-focus-when-clicking-outside-of-a-textbox). Default behavior doesn't remove the keyboard focus when you don't actually set your keyboard focus in a different place. – Thomas Bouman Jun 08 '15 at 08:33
  • How do I do this purely in the style sheet. I have my style sheet hooked up to a .cs file – netgen Jun 09 '15 at 20:11
  • That's not possible, if you want to move your keyboard focus like the way you described it the above is the best solution. PS. You can put it in the .cs file your style sheet is hooked up to. – Thomas Bouman Jun 10 '15 at 07:26
  • Right, How do I do it in the .cs mt style sheet is hooked up to? – netgen Jun 10 '15 at 15:31
  • See the edit I made previously, add `MouseDown="Window_MouseDown"` to your Window or Page and put the other method in your .cs file. – Thomas Bouman Jun 10 '15 at 15:32
  • I cant add it to the window in the style sheet? This does not work but Something like – netgen Jun 10 '15 at 15:40