locked
How can I change the border color of a TextBox when it is focused?

    Question

  • When a TextBox is focused, its border color will be the phone accent color, then how can I change it to other color?

    Based on VS2013 + WP8.1

    Thursday, September 04, 2014 2:17 AM

Answers

  • Edit its template (in the designer select the TextBox, right click, choose "Edit Template.Edit a copy") and change the colour set on the BorderElement's BorderBrush in the Focused visual state (other storyboard entries removed for clarity)

                                        <VisualState x:Name="Focused">
                                            <Storyboard>
                                                <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="BorderElement">
                                                    <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource MyCustomTextSelectionHighlightColorBrush}"/>
                                                </ObjectAnimationUsingKeyFrames>
                                                                                                       </Storyboard>
                                        </VisualState>

    Thursday, September 04, 2014 2:23 AM
    Owner

All replies

  • Edit its template (in the designer select the TextBox, right click, choose "Edit Template.Edit a copy") and change the colour set on the BorderElement's BorderBrush in the Focused visual state (other storyboard entries removed for clarity)

                                        <VisualState x:Name="Focused">
                                            <Storyboard>
                                                <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="BorderElement">
                                                    <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource MyCustomTextSelectionHighlightColorBrush}"/>
                                                </ObjectAnimationUsingKeyFrames>
                                                                                                       </Storyboard>
                                        </VisualState>

    Thursday, September 04, 2014 2:23 AM
    Owner
  •  just on you GotFocus event, add this line:

    textbox1.BorderBrush = new SolidColorBrush(Colors.Cyan);

    • Edited by kingali3000 Friday, September 19, 2014 10:23 AM
    Friday, September 19, 2014 10:23 AM