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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:51:41+00:00 2026-05-25T09:51:41+00:00

I have a really weird issue with Combobox in WPF. I have used it

  • 0

I have a really weird issue with Combobox in WPF. I have used it before in a simpler implementation and thought I knew how it works, but apparently not. The scenario is as follows… I have three classes which are in a parent/child relationship, I have a list of a type AnswerViewModel which I populate in a Combobox. I want the IsSelected property on the class to be the value that is get/set in the Combobox. Below is some of the code, hopefully enough to see what I am referring to.

These are the models.

public class Quiz
{
    public string QuizName {get;set;}
    public List<Question> Questions {get;set;}
}

public class Question
{
    public int QuestionId {get;set;}
    public string QuestionText {get;set;}
    public List<Answer> {get;set;}
}

public class Answer
{
    public int AnswerId {get;set;}
    public string AnswerText {get;set;}
    public bool IsSelected {get;set;}
}

These are the ViewModels

QuizViewModel.cs

// This will create QuestionViewModel for each question.
ObservableCollection<QuestionViewModel> Questions {get;set;}

QuestionViewModel.cs

// This will create AnswerViewModel for each answer
ObservableCollection<AnswerViewModel> Answers {get;set;}

AnswerViewModel.cs

Answer answer;

// ctor
public AnswerViewModel(Answer answer...)
{
    this.answer = answer;
    ...
}

public string AnswerText 
{
    get { return answer.AnswerText; }
    set
    {
        answer.AnswerText = value;
        NotifyPropertyChanged("AnswerText");
    }
}

public bool IsSelected 
{ 
    get { return _answer.IsSelected; }
    set 
    {
        answer.IsSelected = value;
        NotifyPropertyChanged("IsSelected"); // <--- Breakpoint
    }
}              

These are the XAMLs

Quiz.xaml

<ItemsControl ItemsSource="{Binding Questions}" />

Question.xaml

<ComboBox x:Name="answerCombo"
    ItemsSource="{Binding Answers}"
    DisplayMemberPath="AnswerText"
    SelectedValue="{Binding Path=IsSelected}" 
    SelectedValuePath="IsSelected"/>

The Combobox is populated correctly (It is bound to the Collection of AnswerViewModel), but when I make a selection what I expect is to see at the breakpoint is two events. One for the false on the item no longer selected, and true for the new item selected. But instead it never gets hit.

So I scour the web looking for help and found some interesting information and tried a number of things but, so far nothing seems to be complete. For example:

<ComboBox x:Name="answerCombo"
    ItemsSource="{Binding Answers}"
    DisplayMemberPath="AnswerText"
    SelectedValue="{Binding Path=IsSelected}"
    SelectedValuePath="IsSelected">
    <ComboBox.ItemContainerStyle>
        <Style TargetType="{x:Type ComboBoxItem}">
            <Setter Property="IsSelected" Value="{Binding Path=IsSelected, Mode=TwoWay}"/>
        </Style>
    </ComboBox.ItemContainerStyle>
</Combobox>

But this only selects the correct item in the Combobox when drop-down. Which I understand is correct for this markup.

So, in short, I would like to have the IsSelected Property on the AnswerViewModel updated when I select an item in the Combobox. Any help would be greatly appreciated.

If more information is required just let me know.

Thank you,
Obscured

** Update **

Ok, I think I actually resolved it, but still If anyone has suggestions, or thoughts on this, I would still like to hear them.

Here is what I did, I only changed the Combobox xaml as follows:

<ComboBox x:Name="answerCombo"
    ItemsSource="{Binding Answers}"
    DisplayMemberPath="AnswerText"
    SelectedValue="{Binding Path=ItemsSource/, RelativeSource={RelativeSource Self}}">        
    <ComboBox.ItemContainerStyle>
        <Style TargetType="{x:Type ComboBoxItem}">
            <Setter Property="IsSelected" Value="{Binding Path=IsSelected, Mode=TwoWay}"/>
        </Style>
    </ComboBox.ItemContainerStyle>
</Combobox>

Basically this sets the selectedvalue to the current item, and since the itemcontainerstyle handles the case when drop-down it binds the IsSelected property of the combobox to the IsSelected property of my ViewModel. And this appears to do the trick.

  • 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-25T09:51:42+00:00Added an answer on May 25, 2026 at 9:51 am

    Just remove the SelectedValue and SelectedValuePath properties, it’s not how they work. SelectedValuePath indicates which property of the selected item will be the SelectedValue of the ComboBox; if you say that the SelectedValuePath is “IsSelected”, the SelectedValue will be SelectedItem.IsSelected, which is clearly not what you want… And your binding for SelectedValue refers to a property that doesn’t exist (QuestionViewModel.IsSelected)

    This should work for you:

    <ComboBox x:Name="answerCombo"
        ItemsSource="{Binding Answers}"
        DisplayMemberPath="AnswerText">
        <ComboBox.ItemContainerStyle>
            <Style TargetType="{x:Type ComboBoxItem}">
                <Setter Property="IsSelected" Value="{Binding Path=IsSelected, Mode=TwoWay}"/>
            </Style>
        </ComboBox.ItemContainerStyle>
    </Combobox>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

it's a really weird thing - i have a website that works perfectly in
I seem to have stumbled across a really weird issue when posting a static
I have a weird issue with my CSS. Really can't figure this one out.
I have a really weird issue that I can't figure out with comparing objects
I have a really weird issue with Sql queries on unicode data. Here's what
I have a really weird issue with my cout statements. I've only tried this
I'm having an issue with the Singleton pattern. It is really weird, but it
I have a really weird issue with an SQL query I've been working with
this seems to be weird but it really happened. I have this code working
IDE = VS7 or 2002 Hi all, I have a really weird problem here.

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.