WPF : ComboBoxes don’t get set on databinding

This has been a nightmare for a long time for me. I setup the bindings on WPF comboboxes but they never get set to correct items and always are blank on startup. Once I select something, they keep the selection for the rest of the session.

 

Cause:

This happens because the WPF system is unable to determine that the set value is same instance as the object in the list. This is specific to complex data types.

 

Fix:

The data type needs to implement IEquatable<T> interface.

 

References:

http://stackoverflow.com/questions/3506193/wpf-combobox-selecteditem-not-getting-set

Advertisements

About vijayvepa

I'm a software consultant for Software Specialists Inc. currently working at Philips Respironics, Pittsburgh

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: