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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:41:39+00:00 2026-06-10T04:41:39+00:00

I have a ComboBox in wpf that twoway binds between the view and viewmodel.

  • 0

I have a ComboBox in wpf that twoway binds between the view and viewmodel.
Running under .net 4 in win7 everything was working as expected but running my application under windows 8, the combobox can’t seem to get the correct selected item from the viewmodel.

When entering the view the combobox asks for the selected item from the view model
The selected item is returned and my method that overrides “Equals” returns true.
The combobox in the view then either doesn’t register this or does and then ignores it and the next thing that happens is that the View sets the “Selected Item” in the view model to “NULL”.

Is there another way I can achieve the requirements or is it just a bug in running .net 4 apps under .net 4.5 that I’m going to have to live with?

Here is the source. NOTE I bind to the item class and not the enum directly so I can access the [Description] tag for better item names in my combobox.

View

<Controls:KNComboBox Style="{DynamicResource FlowMenuComboBox}" SelectedItem="{Binding ItemsOrder}" ItemsSource="{Binding ItemsOrderValues}" Margin="10,0,0,10"
                                             DisplayMemberPath="Description" SelectedValuePath="{Binding Path=EnumObject}" DisplayString="Sort By:"/>

View Model

private ItemsOrderByItem _itemsOrder;
    public ItemsOrderByItem ItemsOrder
    {
        get
        {
            return _itemsOrder;
        }
        set
        {
            _itemsOrder = value;
            RaisePropertyChanged("ItemsOrder");
            //Methods Called Here Not Important To Question
        }
    }
    public List<ItemsOrderByItem> ItemsOrderValues
    {
        get
        {
            List<ItemsOrderByItem> enumItems = new List<ItemsOrderByItem>();
            foreach (ItemsOrderBy enumValue in Enum.GetValues(typeof(ItemsOrderBy)))
            {
                enumItems.Add(new ItemsOrderByItem(enumValue));
            }
            return enumItems;
        }
    }

The Enum

public enum ItemsOrderBy
{
    [Description("Name")]
    Name,
    [Description("Date Added")]
    DateAdded        
}

The Item Class

public class ItemsOrderByItem
{
    public ItemsOrderByItem(ItemsOrderBy enumValue)
    {
        EnumObject = enumValue;
    }
    public ItemsOrderBy EnumObject;
    public string Description
    {
        get
        {
            return EnumExtension.GetEnumDescription<ItemsOrderBy>(EnumObject);
        }
    }

    public override string ToString()
    {
        return Description;
    }

    public override bool Equals(object obj)
    {
        if (obj is ItemsOrderByItem)
        {
            return ((ItemsOrderByItem)obj).EnumObject == EnumObject;
        }
        else
        {
            return false;
        }
    }
}  
  • 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-10T04:41:41+00:00Added an answer on June 10, 2026 at 4:41 am

    Inspection of the code snippets in your post reveals several problems:

    1. ItemsOrderValues property returns a new value each time it is queried. This is equivalent to changing the value without raising a property-changed notification. Data-binding clients will be confused.

    2. {Binding Path=EnumObject} won’t work. Binding paths use properties; EnumObject is a field.

    3. SelectedValuePath has type string. The binding to EnumObject (if it worked) produces an object of type ItemsOrderBy. After type-conversion, this will set SelectedValuePath to “Name” (or possibly “ItemsOrderBy.Name”). This is legal, but probably not what you wanted. The path is applied to items in the ItemsSource, which have type ItemsOrderByItem; this type doesn’t have a property called “Name”.

    4. The ItemsOrderByItem class has mutable equality semantics, i.e. the result of Object.Equals(x, y) can change, for fixed objects x and y. That’s because the Equals method depends on a publicly-mutable field – EnumObject. This will confuse any code that (legitimately) assumes that once x and y have tested Equal, they will remain Equal.

    5. The class overrides Equals, but doesn’t override GetHashCode. This is forbidden (see docs for either method) because it leads to horrible confusion whenever instances are used in hashtables. Two instances that are Equal but have different hashcodes will corrupt a hashtable. [When you fix this, remember to ensure that an object’s hashcode never changes – this is also a documented requirement.]

    Of these, the last one is probably most responsible for your problem. WPF uses hashtables to help represent the set of selected items, and the exact usage has changed in v4.5. It’s very likely that the unreliable hashing behavior of the ItemsOrderByItem class is causing the confusion.

    If fixing these coding issues still doesn’t solve your problem, please feel free to open connect bug with the repro project.

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

Sidebar

Related Questions

I have a WPF ComboBox that binds to a set of data. I do
I have a combobox in my WPF app that is databound to my list
I have a WPF containing a dynamically created DataGridComboBoxColumn this has a comboBox that
I have a ComboBox on a WPF window that is giving me some heartache,
I have a WPF UserControl that contains a ComboBox . I need to attach
I have a WPF CustomControl that is derived from ComboBox and I'm trying to
I have a WPF / XAML Window that contains a ComboBox that is giving
I have a ComboBox in a WPF application that is bound to an ObservableCollection
I have a WPF ComboBox and I want to go to items that start
I have a WPF combobox that I would like to bind to an observable

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.