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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:18:47+00:00 2026-06-02T03:18:47+00:00

I’m working on a ComboBox that has to have a CheckBox on its items.

  • 0

I’m working on a ComboBox that has to have a CheckBox on its items. I’ve implemented a functionality to attend changes on those checkboxes. Part of that functionality establishes the content of the ComboBox from the CheckBoxes (i.e. when I select ‘pear’, ‘apple’ and ‘blueberry’, the combo has to have those items checked and also its content has
to be ‘pear; apple; blueberry’).

I’ve done it. But, since I’m working with a ComboBox, items are selected whenever I click on the item outside its checkbox so the content is overwritten by the text of the item. This xaml shows how is it written:

<ComboBox   IsEditable="True" DataContext="{Binding}" 
        IsTextSearchEnabled="False" IsReadOnly="True">
<ComboBox.ItemTemplate>
    <DataTemplate >
        <StackPanel Orientation="Horizontal">
            <CheckBox IsChecked="{Binding   Path=EstaSeleccionado, 
                                            Mode = TwoWay, 
                                            UpdateSourceTrigger=PropertyChanged}"/>
            <TextBlock Text="{Binding Path=Item.Value}"/>
        </StackPanel>
    </DataTemplate>
</ComboBox.ItemTemplate>

How do I disable the listitems without disabling the checkboxes?

UPDATE
In your answer try to skip events. I know this can be done more or less clean and easy; but for maintainability concerns I would prefer a property-xaml based solution (i.e. disable events on the ListBoxItem except on the checkbox’s screen area, etc.)

  • 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-02T03:18:49+00:00Added an answer on June 2, 2026 at 3:18 am

    The Checkbox control has a Content area to the right of the Checkbox for adding text, graphics, etc. Instead of setting your text in a separate textblock use the CheckBox’s Conent tag.

    <ComboBox.ItemTemplate>
        <DataTemplate>
            <CheckBox IsChecked="{Binding Path=EstaSeleccionado, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
                <TextBlock Text={Binding Path=Item.Value}/>
            </CheckBox>
        </DataTemplate>
    </ComboBox.ItemTemplate>
    

    Note: the Content tag does not need to be explicitly set, it is assumed that controls between the open and closing Checkbox tags are Content.

    Update:

    Sorry, I misunderstood your question. The problem you’re seeing is that the combobox default behavior is on SelectionChanged is to set the SelectedText to the newly SelectedItem. To change this behavior you have two options:

    1. Override the SelectionChanged event handler in the back code and set the SelectedText programmatically
    2. Bind the SelectedText to a property in your ViewModel. When the binding attempts to change the value have your property inspect the source of the combobox binding and build your SelectedText value from the checked items.

    I’d recommend option #2, something like this:

    Code:

    public class CheckItem // This probably should implement INotifyPropertyChanged
    {
         public string Name { get; set; }
         public bool IsChecked { get; set; }
    }
    
    
    public class ViewModel : INotifyPropertyChanged
    {
        public ObservableCollection<CheckItem> ComboItems { get; set; }
    
        public string SelectedText 
        {
             get { return selectedText; }
             set { 
                 StringBuilder sb = new StringBuilder();
                 foreach (var item in ComboItems)
                     if (item.IsChecked)
                         sb.Append(String.Format("{0}; ", item.Name));
                 selectedText = sb.ToString();
                 // raise property changed here...
             }
        }
    }
    

    XAML:

     <ComboBox ItemsSource="{Binding Path=myViewModel.ComboBoxItems}">
        <ComboBox.ItemTemplate>
            <DataTemplate>
                <CheckBox IsChecked="{Binding Path=IsChecked, Mode=TwoWay>
                    <TextBlock Text={Binding Path=Name}/>
                </CheckBox>
            </DataTemplate>
        </ComboBox.ItemTemplate>
     <Combobox/>
    

    Apologies, I don’t have my compiler handy so some of this might not compile.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a jquery bug and I've been looking for hours now, I can't

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.