C# WPF中的数据表单和二级对象绑定
我在Caliburn.Micro上使用Telerik的WPF控件。尤其是DataForm控件。我试图将它绑定到一个具有以下构造的对象C# WPF中的数据表单和二级对象绑定,c#,wpf,data-binding,telerik,caliburn.micro,C#,Wpf,Data Binding,Telerik,Caliburn.micro,我在Caliburn.Micro上使用Telerik的WPF控件。尤其是DataForm控件。我试图将它绑定到一个具有以下构造的对象 public class FrequencyMap : BindableBase { private Guid id; public Guid ID { get { return id; } set { id = value; OnProper
public class FrequencyMap : BindableBase
{
private Guid id;
public Guid ID
{
get { return id; }
set
{
id = value;
OnPropertyChanged();
}
}
private string procedureCodeId;
public string ProcedureCodeId
{
get { return procedureCodeId; }
set
{
procedureCodeId = value;
OnPropertyChanged();
}
}
private FrequencyChoice frequency;
public FrequencyChoice Frequency
{
get { return frequency; }
set
{
frequency = value;
OnPropertyChanged();
}
}
private DateTime effectiveDate;
public DateTime EffectiveDate
{
get { return effectiveDate; }
set
{
effectiveDate = value;
OnPropertyChanged();
}
}
private DateTime? terminateDate;
public DateTime? TerminateDate
{
get { return terminateDate; }
set
{
terminateDate = value;
OnPropertyChanged();
}
}
}
然后FrequencyChoice
对象如下所示:
public class FrequencyChoice : BindableBase
{
private int id;
private string modifiedUser;
public int ID
{
get { return id; }
set
{
id = value; OnPropertyChanged();
}
}
private string code;
public string Code
{
get { return code; }
set
{
code = value; OnPropertyChanged();
}
}
private string name;
public string Name
{
get { return name; }
set
{
name = value; OnPropertyChanged();
}
}
private string description;
public string Description
{
get { return description; }
set
{
description = value; OnPropertyChanged();
}
}
private string calculationDescription;
public string CalculationDescription
{
get { return calculationDescription; }
set
{
calculationDescription = value; OnPropertyChanged();
}
}
private DateTime inactiveDate;
public DateTime InactiveDate
{
get { return inactiveDate; }
set
{
inactiveDate = value; OnPropertyChanged();
}
}
public string ModifiedUser
{
get
{
return this.modifiedUser;
}
set
{
this.modifiedUser = value;
OnPropertyChanged();
}
}
}
除了Frequency
属性外,这项功能运行得非常好。我如何让它正常工作。我是否必须像本文一样使用Enum
?
如果是这样的话,我该如何将两者联系起来?我想你想要的是一个具有多个频率选择关系的频率图 首先,我会将属性更改为从PropertyChangedBase继承
public class FrequencyChoice : PropertyChangedBase
{
}
然后按如下所示更改您的属性
private BindableCollection<FrequencyChoice> frequencyChoices;
public BindableCollection<FrequencyChoice> FrequencyChoices
{
get
{
return this.frequencyChoices;
}
set
{
if (Equals(value, this.frequencyChoices))
{
return;
}
this.frequencyChoices = value;
this.NotifyOfPropertyChange(() => this.FrequencyChoices);
}
}
私人BindableCollection频率选择;
公共BindableCollection频率选择
{
收到
{
返回此项。频率选择;
}
设置
{
if(等于(值,此.frequencyChoices))
{
回来
}
this.frequencyChoices=值;
this.NotifyOfPropertyChange(()=>this.FrequencyChoices);
}
}
我真的不确定什么是BindableBase(来自google的是Prism,但是你使用Caliburn,所以请使用PropertyChangedBase),但是如果你还想使用它,那就继续吧,但要确保它能为你处理更改通知
由于每张地图都有很多选择,您需要收集来存储这些选择我有Telerik suite,但还没有使用数据表单-将查看它,看看我是否能提供一个答案,因为我已经厌倦了布置网格:)(您还没有找到答案,是吗?)不,还没有找到。我很想听听你的发现。我想频率选择应该是一个多选下拉列表,里面有多个
FrequencyChoice
对象?或者它们应该是可编辑的?你能再解释一下这个类的数据来自哪里吗(它是从预定义的值加载的,还是用户应该在屏幕上编辑它?)。也许这不是我要去的方向。基本上,数据库中有一个名为FrequencyMap的表,它有一个ID、ProcedureCodeId和FrequencyId。ID是“扔掉”的,这个表只是为了让我从所有“可能的”频率选择中提取一个ProcedureCode。有什么意义吗?你希望用户在界面上看到什么?