ComboBox in DataGrid binding
Hi, I have datagrid and I bound some data to each row (ObservableCollection<Contact>) Name, Surname, Group, Address are in Contact object as property. For group column I want to add comboBox, where is some Group Collection
namespace BusinessLayer.Structure
{
public class GroupList : ObservableCollection<Group>
{
public GroupList()
{
Manager.PrepareData _groups = new Manager.PrepareData(); // get ObservableCollection<Group>
foreach(Group group in _groups.LoadGroups())
{
this.Add(group);
}
}
}
}
namespace BusinessLayer.Structure
{
public class Group
{
public Guid ID_Group { get; set; }
public string Name_Group { get; set; }
}
}
namespace BusinessLayer.Structure
{
public class Contact
{
public Guid Id { get; set; };
public string Name { get; set; };
public string Surname { get; set; };
public string Group { get; set; };
public string Address { get; set; };
}
}
How can I bind data in DataGrid in XAML? DataGrid is in PresentationLayer namespace.
<DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<ComboBox x:Name="group_combobox" SelectedValuePath="Name_Group"
SelectedValue="{Binding Group}"
DisplayMemberPath="Name"
ItemsSource="{Binding Path=DataContext.GroupList,
RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}"
IsReadOnly="True" />
</DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>
I tried a lot of ideas but no solution. Could someone help me, please? Thanks