I trying to port a WinForms project to WPF. But I am have some trouble with the Data-Binding.
My WinForms program has DataGrid which uses a column in the form Data Binding Combobox
His **Data** properties:
DataPropertyName **Developer**
DataSource **developerBindingSource1**
DataMember **DeveloperName**
ValueMember **Developer**
And next code
developerBindingSource1.DataSource = DT.Developer;
taskBindingSource.DataSource = DT.Task;
typeTaskBindingSource.DataSource = DT.TypeTask;
developBindObjBindingSource.DataSource = DevelopBindObj.GetBindingList(DT.Developer);
typeTaskBindObjBindingSource.DataSource = TypeTaskBindObj.GetBindingList(DT.TypeTask);
I use additional class for dataBinding
class DevelopBindObj
{
public Developer Developer { get; private set; }
public string DeveloperName
{
get
{
return this.Developer.FIO;
}
}
private DevelopBindObj(Developer Developer)
{
this.Developer = Developer;
}
public static IBindingList GetBindingList(IEnumerable<Developer>Developers) {BindingList<DevelopBindObj> result = new BindingList<DevelopBindObj>();
foreach (var ee in Developers)
{
result.Add(new DevelopBindObj(ee));
}
return result;
}
And how can I do it in WPF?
I’ve tried:
<DataGridComboBoxColumn x:Name="iDTypeTaskColumn"
Header="IDType Task"
Width="SizeToHeader"
SelectedValuePath="{Binding Source={StaticResource bindObjectsTaskViewSource}, Path=TypeTask}"
DisplayMemberPath="{Binding Source={StaticResource bindObjectsTaskViewSource}, Path=TypeTaskName}"
ItemsSource="{Binding Source={StaticResource bindObjectsTaskViewSource}}" SelectedItemBinding="{Binding Path=tblDevTypeTask}">
But this doesn’t work.
SelectedValuePathandDisplayMemberPathshould be property names on the items in theComboBox, not bindingsWhere
bindObjectsTaskViewSourceis a collection of objects, and each object in that collection has a property calledTypeTaskandTypeTaskName