0

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.

Community
  • 1
  • 1
user3263192
  • 499
  • 1
  • 4
  • 14

1 Answers1

1

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.

dovid
  • 6,354
  • 3
  • 33
  • 73
  • without the `public` qualifier, shouldn't this work with just the `{get; set;}` since C# defaults to `internal` and that should still be accessible? – Dakotah Hicock Jul 27 '15 at 20:32
  • no. must be **public**. probably because the logic of control Is an external assembly. – dovid Jul 28 '15 at 09:12