I want to bind a xamwebcomboeditor to the distinct values of a linq query. It will bind, but I don't know what to set the DisplayMemberPath to. Here is the vb code:
cboCategory.ItemsSource = (From m in mccodes Select m.Category).Distinct()
I've tried DisplayMemberPath="{Binding}", DisplayMemberPath="{Binding Value}" and DisplayMemberPath = "Category". In every case the combo has 13 blank items in it.
I assumed that the Category was a string field.
what you are going to want to do is have you linq create objects if you want to use the display member path:
Code
public class Person
{
public string Name { get; set; }
// imagine a lot of other fields thought
}
public class PersonProxy
public string NameProxy{get ; set;}
void edit_Loaded(object sender, RoutedEventArgs e)
ObservableCollection<Person> groupOfPeople = new ObservableCollection<Person>();
groupOfPeople.Add(new Person() { Name = "bob" });
groupOfPeople.Add(new Person() { Name = "Joe" });
var x = from name in ((from _person in groupOfPeople select _person.Name).Distinct()) select new PersonProxy() { NameProxy = name };
this.edit.ItemsSource = x;
Xaml
<ig:XamComboEditor x:Name="edit" Width="200" Height="30" DisplayMemberPath="NameProxy"></ig:XamComboEditor>
So what this code is doing is making a list of the proxy objects and populating from the data gathered from the real list. then we bind the list to combo editor control.