I'm trying to include a ComboBox column in a WPF datagrid. I'm trying to bind this column to an observable collection in the ViewModel however, at run time the cells remain empty. Datacontext is correct, as all normal columns bind successfully. I want to display 'regionShortCode' in the UI. Here's my xaml:
<DataGridComboBoxColumn Header="Region" DisplayMemberPath="regionShortCode" Width="SizeToHeader">
<DataGridComboBoxColumn.ElementStyle>
<Style>
<Setter Property="ComboBox.ItemsSource" Value="{Binding Path=MembershipsCollection}" />
</Style>
</DataGridComboBoxColumn.ElementStyle>
<DataGridComboBoxColumn.EditingElementStyle>
<Style>
<Setter Property="ComboBox.ItemsSource" Value="{Binding Path=MembershipsCollection}" />
</Style>
</DataGridComboBoxColumn.EditingElementStyle>
</DataGridComboBoxColumn>
& here is my ObservableCollection declared in the ViewModel. The Collection is populated successfully from a method invoked in the constructor:
private ObservableCollection<tbAccountMembership> _MembershipsCollection;
public ObservableCollection<tbAccountMembership> MembershipsCollection
{
get { return _MembershipsCollection; }
set
{
_MembershipsCollection = value;
OnPropertyChanged("MembershipsCollection");
}
}
At run time I get:
System.Windows.Data Error: 40 : BindingExpression path error: 'MembershipsCollection' property not found on 'object' ''tbAccountMembership_041E43AFC29975F12C156BA1373ACD47FC07BBE55614E5AF8AD3BBD9F090C133' (HashCode=46247020)'. BindingExpression:Path=MembershipsCollection; DataItem='tbAccountMembership_041E43AFC29975F12C156BA1373ACD47FC07BBE55614E5AF8AD3BBD9F090C133' (HashCode=46247020); target element is 'TextBlockComboBox' (Name=''); target property is 'ItemsSource' (type 'IEnumerable')
in the Output window. Why can't the Xaml resolve this binding? Thanks
RelativeSource Binding.ObservableCollection<T>declared?