从WinForm移植到WPF时,数据绑定出现问题
我正在尝试将WinForms项目移植到WPF。但是我在数据绑定方面遇到了一些问题 我的WinForms程序有DataGrid,它使用表单数据绑定组合框中的一列从WinForm移植到WPF时,数据绑定出现问题,wpf,data-binding,Wpf,Data Binding,我正在尝试将WinForms项目移植到WPF。但是我在数据绑定方面遇到了一些问题 我的WinForms程序有DataGrid,它使用表单数据绑定组合框中的一列 His **Data** properties: DataPropertyName **Developer** DataSource **developerBindingSource1** DataMember **DeveloperName** ValueMember **Developer** 下一个代码是什么 developerB
His **Data** properties:
DataPropertyName **Developer**
DataSource **developerBindingSource1**
DataMember **DeveloperName**
ValueMember **Developer**
下一个代码是什么
developerBindingSource1.DataSource = DT.Developer;
taskBindingSource.DataSource = DT.Task;
typeTaskBindingSource.DataSource = DT.TypeTask;
developBindObjBindingSource.DataSource = DevelopBindObj.GetBindingList(DT.Developer);
typeTaskBindObjBindingSource.DataSource = TypeTaskBindObj.GetBindingList(DT.TypeTask);
我使用附加类进行数据绑定
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;
}
class-developbinobj
{
公共开发人员开发人员{get;private set;}
公共字符串DeveloperName
{
得到
{
返回此.Developer.FIO;
}
}
私人开发商印度银行(开发商)
{
this.Developer=Developer;
}
公共静态IBindingList GetBindingList(IEnumerableDevelopers){BindingList结果=新BindingList();
foreach(开发者中的var-ee)
{
结果。添加(新开发的INDOBJ(ee));
}
返回结果;
}
我怎样才能在WPF中做到这一点
我试过:
<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}">
但这不起作用。您的
bindObjectsTaskViewSource
是否在资源中的任何位置声明,以便以这种方式访问它。。。
{StaticResource bindObjectsTaskViewSource}
如果没有,那么您应该首先学习WPF的基础知识,以了解
Source
作为StaticResource
和Source
作为DataContext
SelectedValuePath
和displayemberpath
之间的区别,应该是组合框中项目的属性名称,而不是绑定
<DataGridComboBoxColumn x:Name="iDTypeTaskColumn"
Header="IDType Task"
Width="SizeToHeader"
SelectedValuePath="TypeTask"
DisplayMemberPath="TypeTaskName"
ItemsSource="{Binding Source={StaticResource bindObjectsTaskViewSource}}"
SelectedItemBinding="{Binding Path=tblDevTypeTask}">
其中,bindObjectsTaskViewSource
是对象的集合,该集合中的每个对象都有一个名为TypeTask
和TypeTaskName