Here is what i have:
- a SQL CE database, that holds this Category table, with id and name columns only.
- dbml generated with sqlmetal
- singleton (static class) that exposes the linq DataContext.
in the code-behind file, i have a property like follows:
private System.Data.Linq.Table Categories { get { return LibraryDataStore.Instance.Categories; } }
I want to simply bind the categories to a combobox. Can't believe i've been at it for hours now, with no result :( I don't want to set ItemsSource in the code behind, I want to do this XAML-only, but how? Most examples i found were defining the data right there in XAML, or setting ItemsSource programatically, but that is not what i want.
Why isn't this, for example, working?
<ComboBox Name="cmbCategory"
Margin="3"
MinWidth="200"
ItemsSource="{Binding Path=Categories}"
DisplayMemberPath="Name"/>
As a side note, i want to say that I find the databinding model of wpf extremely difficult to learn, as it is so thick and there are just SO MANY WAYS to do things.
Later edit: I found that it works if i set the ItemsSource like this:
var cats = from c in LibraryDataStore.Instance.Categories
select c;
cmbCategory.ItemsSource = cats;
Still, I can't figure it out why it doesn't work in XAML.