Binding Combobox to custom list windows phone

I have a custom list with structure category -id -name -color I create a list and bind it to combobox name categoryListBox in my xaml page.

I have tried using this piece of code

List<category> categoryCollection = await       categoryList.GetCategoryListAsync();
categoryListBox.ItemsSource = categoryCollection;
categoryListBox.DisplayMemberPath = "name";
categoryListBox.SelectedValuePath = "id";

using this as resource

Whenever I run the app, all I get is a blank screen, although when I get collection of items using

 var item = categoryListBox.Items;

it shows it of type System.Generic.Lists having the number of items it should have. I seem to be on a standstill here, and don't know whats wrong with it. I even looked at an example, but couldn't understand much.

This is the definition of combobox

 <ComboBox 
     Canvas.ZIndex="100"
     Name="categoryListBox"
     Foreground="Black"
     Margin="10,0"
     PlaceholderText="Select.."  
     Style="{StaticResource ComboBoxStyle1}"/>

And here is the file for category class.

Answers


the values in DisplayMemberPath and SelectedValuePath properties must be a property name (not variable), and accessible (public modifier).

so if you edit your category class, by replacing this:

int id;
string name;
int color;

with:

public int id { get; set; }
public string name { get; set; }
public int color { get; set; }

It should work.


Need Your Help

Search for Bluetooth devices and display using android programming

java android bluetooth

Hey Guys this may a silly question but I am a bit confused . So I need a help and I am new to android . Here Is my code that I have that I have tried

Fixed element alignment to always stick to the bottom of the screen

css css-float

I have a fixed element that is a small menu with a few links that will follow you on the page.