I'm totally new at WPF and I'm stuck with the bellow situation:
class Person{
string Name;
List<Address> ListAddresses;
}
I have a DataGrid with ItemsSource as an ObservableCollection<Person>
. This collection is in MainViewModel
class.
I want to create a DataGridComboBoxColumn
with the addresses.
<DataGrid ItemsSource="{Binding Persons, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}">
<DataGrid.Columns>
<DataGridComboBoxColumn ItemsSource="{Binding Path=ListAddresses, RelativeSource={RelativeSource Mode=FindAncestor,
AncestorType={x:Type local:Person}}}">
</DataGridComboBoxColumn>
</DataGrid.Columns>
</DataGrid>
I receive the following error:
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='PersonApp.UL.ViewModels.Person', AncestorLevel='1''. BindingExpression:Path=ListAddresses; DataItem=null; target element is 'DataGridComboBoxColumn' (HashCode=11440639); target property is 'ItemsSource' (type 'IEnumerable')
MainViewModel
, so you're using the MVVM structure? – Keyur PATEL