Feb 13, 2009 at 11:58 PM
Edited Feb 13, 2009 at 11:59 PM
I figured I should continue this thread as this was what essentially solved my problem. I am using a DataGrid in a UserControl that is bound to my EntryListViewModel. The EntryListViewModel contains an ObservableCollection<EntryViewModel>
of viewmodels that encapsulate the actual entry business objects. It is this collection which is what the DataGrid is bound to.
The main view model has the list of accounts which are intended to be shown in a drop down list for the Account field of each entry. The EntryListViewModel has a property called AccountList which supplies this list. To make things simple each EntryViewModel
item can access the AccountList property from the EntryListViewModel through a _parent field, so EntryViewModel also provides AccountList as a property. So then I tried to do some simple databinding the a ComboBox and first tried this:
That did not work I got errors like this when I click on the combobox and the box has nothing in it. It does not populate with the objects from the collection:
System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:Path=AccountList; DataItem=null; target element is 'DataGridComboBoxColumn' (HashCode=23741667); target property is 'ItemsSource'
So I found this post and tried it the way you've shown above:
Now this works, though I do still get the same error message, but only once when I first click on the combobox. It is populating the box though so I am happy about that.
So what I would like to know is why do I have to do all this work? The first example should honestly be more than functional. Why do I have to respond to style triggers to get the binding to work
here? It seems like a whole lot of XAML to do something extremely simple.
(I would also like to know why this edit box is so frustratingly hard to use and how you are formatting the code on your posts ;-)