<p>I am attempting to use the following template for a column, the combobox is filled correctly when not embedded into the datagrid, and not bound at all when added to the editor template.<br /></p>
<p><ComboBox ItemsSource="{Binding AbsCodes, ElementName=userControl, Mode=OneWay}" DisplayMemberPath="AbsCode"><ComboBox.DataContext><HQPORTAL_HRPoints:AbsCodeRefContract/></ComboBox.DataContext></ComboBox></p>
Hi,
So, i believe in a TemplateColumn the DataContext of the element in the Template is set when its loaded, as it led to the best performance with virtualization. I can look into other ways of doing this, but for now, can you try wrapping your ComboBox in another element in the DataTemplate?
<DataTemplate>
<Border><ComboBox /> </Border
</DataTemplate>
-SteveZ
Unfortunately that did not work. I would assume the problem is related to control initialization, but the column remains empty for late / early bound records the same. The scenario in this instance is a combo box that is pointed at a property which is inturn latebound via an asynchronous call to a wcf webservice which gathers data from our sql backend (LINQ). I could use the row adding event to populate the combo box for each row, but I would be getting away from the mvvm approach. Any other suggestions?
Hmm. I think i missed something with your snippet before. Are you trying to use an ElementName in the binding? First, that will cause the DataContext on your comboBox to be ignored and second i believe the ElementName will not be resolved, as i believe the elements have to be within the same naming container.
If the binding occurs, later, then you also need to make sure, that the property your binding to on your object implements INotifyPropertyChanged and raises the PropertyChanged event when the data is updated so that the combo can be notified.
The element name property is generated from the designer, the purpose was to bind to a property that is located in the parent control but still in the local visual tree. I tried the INotifyPropertyChanged to no avail. I was able to get the functionality I needed by including the list as a DataMember for the WCF DataContract, it's a little bulky but it does the trick for now. I would still like to get the INofityPropertyChanged implementation to work though, the built in editor validation looks like it will be very useful. Thank you for taking the time on this Stephen, have a good weekend.