Sameel
Sameel

Reputation: 115

How to select item displayed by DisplayMemberPath in wpf ComboBox?

I have a ComboBox control and I am getting the ItemsSource of the control from a Web Service (Asp.Net WebApi 2), the code of which is as follows:

cmb_Class.ItemsSource = from c in Container.Classes select new {ClassID = c.Class_Id};
cmb_Class.DisplayMemberPath = "ClassID";

I had used DisplayMemberPath so that I can only get the assigned value.

But,

The problem is that when I select an item from the drop down menu, instead of that item the whole string is shown as selected item in the Combobox.

The Image of my problem for better understanding is as follows:

enter image description here

Please, tell me how can I solve this issue?

Upvotes: 1

Views: 680

Answers (2)

Yokomoko
Yokomoko

Reputation: 137

Just to add an actual solution for the WatermarkComboBox. It appears that the WatermarkComboBox is missing a part of the XAML.

I would create a style for this ComboBox with Blend, and then under / within the line:

<ContentPresenter x:Name="ContentSite" 

add in the following line of XAML:

ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"

This will resolve the problem.

Upvotes: 0

Sameel
Sameel

Reputation: 115

My Problem is solved.

I was using the WatermarkCombobox control of ExtendedWpfToolkit when I changed it to the default wpf Combobox control, my problem got solved.

Upvotes: 1

Related Questions