Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 863611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T09:20:27+00:00 2026-05-15T09:20:27+00:00

I have a Window that has two primary areas. One is a TextBox inside

  • 0

I have a Window that has two primary areas. One is a TextBox inside of a ScrollViewer and the other is a TabControl. I want to have a red border around the part that currently has focus, so I wrote the following code to do that

Xaml

<ScrollViewer BorderBrush="Red" 
              BorderThickness="0"
              GotFocus="Border_GotFocus"  
              LostFocus="Border_LostFocus">
    <TextBox/>
</ScrollViewer>
<TabControl BorderBrush="Red" 
            BorderThickness="0"
            GotFocus="Border_GotFocus"  
            LostFocus="Border_LostFocus">
</TabControl>

Code

private void Border_LostFocus(object sender, RoutedEventArgs e)
{
    var control = sender as Control;
    if (control != null)
    {
        control.BorderThickness = new Thickness(0);
    }
}

private void Border_GotFocus(object sender, RoutedEventArgs e)
{
    var control = sender as Control;
    if (control != null)
    {
        control.BorderThickness = new Thickness(2);
    }
}

The problem is that if I click on the TextBox it does not update the border around the ScrollViewer. If I click on a Tab in the TabControl it updates the border so that I can see the border, but doesn’t “remove” it when I click somewhere else. Is there some better way to do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T09:20:28+00:00Added an answer on May 15, 2026 at 9:20 am

    First off, I’d highly recommend not using code and keeping this all in XAML.

    Secondly, I’d also recommend using a Border to do this.

    Third, I’d use IsKeyboardFocusedWithin in your style trigger.

    <Window.Resources>
        <Style x:Key="FocusedBorder" TargetType="Border">
            <Setter Property="BorderThickness" Value="2"></Setter>
            <Setter Property="BorderBrush" Value="Transparent"></Setter>
            <Style.Triggers>
                <Trigger Property="IsKeyboardFocusWithin" Value="True">
                    <Setter Property="BorderBrush" Value="Red"></Setter>
                </Trigger>
            </Style.Triggers>
        </Style>
    </Window.Resources>
    <StackPanel Width="400">
        <ScrollViewer>
            <Border Style="{StaticResource FocusedBorder}">
                <TextBox>
                </TextBox>
            </Border>
        </ScrollViewer>
        <TabControl>
            <TabItem Header="Foo">
                <Border Style="{StaticResource FocusedBorder}">
                    <TextBox></TextBox>
                </Border>
            </TabItem>
            <TabItem Header="Bar">
                <Border Style="{StaticResource FocusedBorder}">
                    <TextBox></TextBox>
                </Border>
            </TabItem>
        </TabControl>
    </StackPanel>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have an application that has a primary window, it can launch multiple other
I have a HUD window that has some labels on it, and I want
I have a window that has two layers: a static background and a foreground
I have a window in one assembly that has a TextBlock control that I
I have a simple ExtJS 4 (xtype form) inside a window. It has two
This one has me beat; I have a WPF window with two (important for
I have an activeX control that contains one window that has streaming video being
I have a solution, that has two projects, the main one and a small
I have a main tabController that has two tabs, first one is selected as
recently I have tried to achieve a navigation bar that has two sides, one

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.