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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:00:09+00:00 2026-05-27T00:00:09+00:00

I have this same problem, but the solution presented isn’t working, nor is any

  • 0

I have this same problem, but the solution presented isn’t working, nor is any other I’ve found. I want to create a ComboBox with CheckBoxes as part of the ItemTemplate. This has been accomplished. But the problem arises when the user clicks a CheckBox: the PopUp closes. I need it to stay open.

I tried handling the ComboBox.SelectionChanged event and the CheckBox.Click event, but I can’t get it. From tracing through the code, it appears that the SelectionChanged event doesn’t fire at all when the user clicks the CheckBox, which is matches the behavior of the control as nothing appears in the TextBox portion.

This is not for multiple selection, but rather to have the CheckBox bind to a property in the data context.

Here is some sample code

<Toolbar VerticalAlignment="Top">
    <ComboBox x:Name="comboBox" SelectionChanged="ComboBox_SelectionChanged">
        <ComboBox.ItemTemplate>
            <DataTemplate DataType="local:MyType">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition/>
                    </Grid.ColumnDefinitions>
                    <CheckBox Click="CheckBox_Clicked"/>
                    <TextBlock Text="{Binding Title}" Grid.Column="1"/>
                </Grid>
            </DataTemplate>
        </ComboBox.ItemTemplate>
        <local:MyType Title="item 1"/>
        <local:MyType Title="item 2"/>
        <local:MyType Title="item 3"/>
        <local:MyType Title="item 4"/>
    </ComboBox>
</Toolbar>

private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    // do some stuff
}

private void CheckBox_Clicked(object sender, RoutedEventArgs e)
{
    // change a property on the data context if not data bound

    // Tried this, but Popup just closes then reopens
    comboBox.IsDropDownOpen = true;
    // This seems to have no effect
    e.Handled = true;
}

Can anyone help?

EDIT:

I noticed that there is a difference of behavior when the ComboBox is placed in a Toolbar. When not in the Toolbar, it behaves as expected: the CheckBox changes state without closing the Popup. But in the ToolBar, the Popup closes on the first click, regardless of where the click is. Try the new code, please. I really need this in a toolbar.

EDIT 2:

For posterity and anyone searching for it, MS suggested setting the Focusable property of the CheckBox in the DataTemplate to false. This achieves the desired effect.

  • 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-27T00:00:09+00:00Added an answer on May 27, 2026 at 12:00 am

    It seems that the Toolbar control affects the ComboBox control in some way. And strangely, the ComboBox isn’t closed when you put the cursor inside the TextBox, but works wrong with the CheckBox.

    The quickest way to solve this issue is to change focus manually when a user clicks the CheckBox.
    I use the following sequence of steps:

    1) Handle the GotFocus event for every control in the application

    2) Leave only events of the CheckBox control

    3) Check whether the CheckBox is inside the current ComboBox

    4) If yes, return focus to the ComboBox

        public MainWindow()
        {
            InitializeComponent();
    
            //...
    
            comboBox.AddHandler(FrameworkElement.GotFocusEvent, (RoutedEventHandler)OnGotFocus);
        }
    
        private void OnGotFocus(object sender, RoutedEventArgs e)
        {
            if (e.OriginalSource is CheckBox)
            {
                var comboBox = (ComboBox)sender;
                var comboBoxItem = GetParentElement<ComboBoxItem>(e.OriginalSource);
    
                if (comboBoxItem != null && comboBox.Items.OfType<object>().Select(comboBox.ItemContainerGenerator.ContainerFromItem).Contains(comboBoxItem))
                    comboBox.Focus();
            }
        }
    
        private T GetParentElement<T>(object element) where T : DependencyObject
        {
            var current = element as DependencyObject;
    
            while (current != null && !(current is T))
            {
                current = VisualTreeHelper.GetParent(current);
            }
    
            return current as T;
        }
    

    It is a quite messy solution, but anyway it works.

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

Sidebar

Related Questions

I have basically the same problem outlined in this question, however I am using
This is pretty much the same problem i have, except with very different code:
I have this Java code, and I want to do the same thing in
I have an ObjectDataSource (but perhaps this question is the same for all kinds
I have got a problem and a solution, but I am not really satisfied
Does setting this value have the same effect as setting the debug=true in the
This is what I have right now for a file residing on the same
I have two web applications in the same server like this: /basedir/app1path/default1.aspx /basedir/app2path/default2.aspx How
I have roughly 12 computers that each have the same script on them. This
In this the catalog.xml file. I have two books who have the same inventory

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.