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 6723137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:31:59+00:00 2026-05-26T09:31:59+00:00

I have tabItems with TextBox on their headers. I use LostFocus and MouseDoubleClick events

  • 0

I have tabItems with TextBox on their headers. I use LostFocus and MouseDoubleClick events to set the text to the TextBox.

<TabControl>
                <TabItem Width="50">
                    <TabItem.Header>
                        <TextBox Text="text" IsReadOnly="True" LostFocus="TextBox_LostFocus" MouseDoubleClick="TextBox_MouseDoubleClick"/>
                    </TabItem.Header>
                </TabItem>
</TabControl>

    private void TextBox_MouseDoubleClick(object sender, MouseButtonEventArgs e)
    {
        TextBox text_box = sender as TextBox;
        if (text_box == null) { return; }

        text_box.IsReadOnly = false;
        text_box.SelectAll();
    }

    private void TextBox_LostFocus(object sender, RoutedEventArgs e)
    {
        TextBox text_box = sender as TextBox;
        if (text_box == null) { return; }

        text_box.IsReadOnly = true;
    }

LostFocus event happens if only you click on the TabItem header area outside the TextBox or on enother TabItem.
Clicking the tab item content area doesn’t fire lost focus event.

How to make the TextBox to lose focus when user click any area outside the TextBox?

  • 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-26T09:31:59+00:00Added an answer on May 26, 2026 at 9:31 am

    To lost Focus, in other word to get Focus at inside tab content(target):

    1. Focusable of the target is set as true
    2. The target should be hit testable. Background of the target should not be null.
    3. Add event handler to PreviewMouseDown event(NOTE: NOT MouseDown) to react to mouse click.
      If you except 3 step, you application will react only to TAB key.

      <TabControl>
          <TabItem Width="50">
              <TabItem.Header>
                  <TextBox 
                      Text="text" IsReadOnly="True" 
                      LostFocus="TextBox_LostFocus"
                      MouseDoubleClick="TextBox_MouseDoubleClick"/>
              </TabItem.Header>
              <Border Focusable="True" Background="Transparent" PreviewMouseDown="Border_PreviewMouseDown"/>
          </TabItem>
      </TabControl>
      
      
      private void Border_PreviewMouseDown(object sender, MouseButtonEventArgs e)
      {
          var uiElement = sender as UIElement;
          if (uiElement != null) uiElement.Focus();
      }
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WPF TabControl with two TabItems. Each TabItem contains a ListBox with
I have a TabControl with multiple TabItems. In each TabItem there needs to be
I have tabControl in the form. In one of the tabItems I have textbox(myTextBox).
I currently have a custom TabItem which has a custom header, which is defined
I have a WPF TabControl that has a couple of buttons in the TabItem
I have a TabControl bound to a collection and a DataTemplate for the TabItems.
I have a number of usercontrols inside tabitems in a tabcontrol in a main
have a TextBox item (MyTextBox) on a TabItem control. I have code that looks
I have two text box. If 1 of the textbox.text is empty, the MessageBox
I have the following TabControl: <TabControl x:Name=Networks> <TabControl.ItemTemplate> <DataTemplate> <StackPanel Orientation=Horizontal> <TextBlock Text={Binding DisplayName}

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.