Leaving a dropped down ComboBox swallows focus in WPF
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Leaving a dropped down ComboBox swallows focus in WPF

  1. #1
    Join Date
    Apr 2014
    Posts
    2

    Leaving a dropped down ComboBox swallows focus in WPF

    I have the following problem: on a WPF window I placed a combo box and a button. I drop down the combo box and while the combo box is still dropped down I click on the button. The button does not react on the mouse click but the dropped down combo box closes. After a second mouse click the button reacts. And here's the code sample:

    Code:
    <Window x:Class="WpfApplication1.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Height="100" Width="300">
        <Grid>
            <ComboBox VerticalAlignment="Top" HorizontalAlignment="Left"
                      Width="100" IsSynchronizedWithCurrentItem="True" >
                <ComboBoxItem Content="item 1"/>
                <ComboBoxItem Content="item 2"/>
                <ComboBoxItem Content="item 3"/>
            </ComboBox>
            <Button Content="Test" VerticalAlignment="Bottom" HorizontalAlignment="Right"
                    Width="100" Click="Button_Click" />
        </Grid>
    </Window>
    and the code behind:

    Code:
    private void Button_Click(object sender, RoutedEventArgs e)
    {
        MessageBox.Show("Button clicked");
    }
    How can I prevent the combo box to swallow the focus on the button? Thanks.

    regards mc

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,357

    Re: Leaving a dropped down ComboBox swallows focus in WPF

    Are you sure that this isn't the standard behavior? In that, the first click (over the button) is going to move the focus to the button and it will take another click to actually click the button.

    Try it in a WinForm or on an html page. I'll bet you see the same behavior.

  3. #3
    Join Date
    Apr 2014
    Posts
    2

    Re: Leaving a dropped down ComboBox swallows focus in WPF

    I didn't say this is the default behavior. I want to override the described behavior.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center