Gather a Combobox WPF from the service
source link: https://www.codesd.com/item/gather-a-combobox-wpf-from-the-service.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Gather a Combobox WPF from the service
I am trying to populate my combobox from a service response. The service returns an array of object like following
MyService.FirmSocial[] firmSocialList = client.GetActiveSocialMediaTypes();
I have checked, the firmSocialList populates properly. I need to populate my combobox with these values.
I have tried this in my code behind
cbSocialMediaTypes.ItemsSource = firmSocialList;
cbSocialMediaTypes.DisplayMemberPath = "socialMediaValue";
cbSocialMediaTypes.SelectedValuePath = "socialMediaType";
I also tried the same thing on the XAML side, but all I am getting is bunch of empty strings in my combobox. The thing is though, the number of elements matches with the item count of the combobox (of empty strings).
And yes, the property names of the FirmSocial object is correct.
The FirmSocial class
public class FirmSocial
{
private int socialMediaType;
private string socialMediaValue;
public int SocialMediaType
{
get
{
return socialMediaType;
}
set
{
socialMediaType = value;
}
}
public string SocialMediaValue
{
get
{
return socialMediaValue;
}
set
{
socialMediaValue = value;
}
}
}
And I have also tried this in my XAML section;
<ComboBox x:Name="cbSocialMediaTypes" HorizontalAlignment="Left" Margin="56,8,0,0" VerticalAlignment="Top" Width="211"
ItemsSource="{Binding firmSocialList}"
DisplayMemberPath="socialMediaType"
SelectedValuePath="socialMediaType" />
Thanks.
DisplayMemberPath is case sensitive.
DisplayMemberPath="socialMediaType"
is saying trying to bind to your private field, not your public property. Try:
DisplayMemberPath="SocialMediaType"
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK