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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T13:24:04+00:00 2026-06-02T13:24:04+00:00

The following behaviour is occurring with the .net 4.0 code set out further below:

  • 0

The following behaviour is occurring with the .net 4.0 code set out further below:

Click on textbox so it gains focus, and then click button:

  1. As code stands, lostfocus handler is called, but not buttonclick handler
  2. Comment out MessageBox.Show(“handlelostfocus”) and then click handler is called
  3. Set breakpoint in handlelostfocus and breakpoint is hit, but click handler is not called

Are these bugs or behaviour by design – if later, is there any further explanation?

<Window x:Class="WpfApplication4.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="MainWindow" Height="350" Width="525">
        <Grid>
            <Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="216,194,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" />
            <TextBox Height="23" HorizontalAlignment="Left" Margin="197,108,0,0" Name="textBox1" VerticalAlignment="Top" Width="120" />
        </Grid>
    </Window>

public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            textBox1.LostFocus += new RoutedEventHandler(handlelostfocus);
        }

        private void handlelostfocus(object sender, RoutedEventArgs e)
        {
            MessageBox.Show("handlelostfocus");
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            MessageBox.Show("click");
        }
    }
  • 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-06-02T13:24:05+00:00Added an answer on June 2, 2026 at 1:24 pm

    The ‘click’ in this case never occurs because as H.B. indicated you are interrupting the UI/event logic by showing the modal messagebox so there is never a mouse down event on the button.

    Try replacing the messagebox with a non-modal wndow such as this:
    new Window() { Width = 300, Height = 100, Title = “handlelostfocus” }.Show();

    and you will see that the events still occur because you are not drawing the focus away from the main window in the middle of the event logic.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have tried the following code: $('a.buildMenu').click(function (event) { // Prevent normal behaviour event.preventDefault();
I observe the following strange behaviour in Vim 7.3: When I'm below a fold,
The following code examines the behaviour of the float() method when fed a non-ascii
Is the following behaviour some feature or a bug in C# .NET? Test application:
Can someone explain the following behaviour: class derivedset1(frozenset): def __new__(cls,*args): return frozenset.__new__(cls,args) class derivedset2(set):
I am curious why I am getting the following behaviour in my code. #include
Can anyone explain the following behaviour to a relative newbie... const char cInputFilenameAndPath[] =
I would like to implement the following behaviour: I have a special media player,
I'd like to produce following behaviour: User in the browser saves some entity. After
I am having trouble implementing the following behaviour in a dropdown menu with jQuery.

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.