我正在尝试将字段绑定到控件,我正在像这样生成 whem:
private void GenerateForm<T>() where T : new()
{
var type = typeof(T);
InputGrid.Children.Clear();
int i = 0;
foreach (var property in type.GetFields(Flags))
{
InputGrid.RowDefinitions.Add(AutoSizeRowDefinition);
var textBlock = new TextBlock { Text = property.Name, Margin = _margin };
Grid.SetRow(textBlock, i++);
InputGrid.Children.Add(textBlock);
InputGrid.RowDefinitions.Add(AutoSizeRowDefinition);
var control = GetControl(property);
Grid.SetRow(control, i++);
InputGrid.Children.Add(control);
}
InputGrid.RowDefinitions.Add(AutoSizeRowDefinition);
var button = new Button { Content = "Отправить", Margin = _margin, MinHeight = 60};
button.Click += GetButtonClick<T>();
Grid.SetRow(button, i);
InputGrid.Children.Add(button);
}
所以我无法创建属性,因为它是“添加引用”自动生成的生成字段的类,而不是属性
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.18058")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://api.service.soap.emias.lanit.ru/")]
public partial class appointmentReceptionToDoctor : object, System.ComponentModel.INotifyPropertyChanged {
private string doctorSpecialityCodeField;
private string doctorSpecialityField;
... and so on
那么我应该如何为所有这些东西绑定它们呢?可能会在运行时生成具有类似字段的属性的类,然后将它们转换回来,但这似乎很复杂。
补充:有些类是用属性正确生成的,有些类是用公共字段生成的。我不知道为什么。我正在尝试重新映射它们,但现在远程不可用。
我这样添加:
我得到这样的课程
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
[System.ServiceModel.MessageContractAttribute(WrapperName="getLpusInfo", WrapperNamespace="http://api.service.soap.emias.lanit.ru/", IsWrapped=true)]
public partial class getLpusInfo {
[System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://api.service.soap.emias.lanit.ru/", Order=0)]
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string omsNumber;
[System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://api.service.soap.emias.lanit.ru/", Order=1)]
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string omsSeries;
[System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://api.service.soap.emias.lanit.ru/", Order=2)]
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public System.DateTime birthDate;
[System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://api.service.soap.emias.lanit.ru/", Order=3)]
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string lpuTypeCode;
[System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://api.service.soap.emias.lanit.ru/", Order=4)]
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string lpuName;
[System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://api.service.soap.emias.lanit.ru/", Order=5)]
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string baseLpuAddress;
[System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://api.service.soap.emias.lanit.ru/", Order=6)]
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public Lanit.Emias.RemoteServices.Appointment.PGUServicesInfo.serviceLpuAddress serviceLpuAddress;
[System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://api.service.soap.emias.lanit.ru/", Order=7)]
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string externalSystemId;
public getLpusInfo() {
}
public getLpusInfo(string omsNumber, string omsSeries, System.DateTime birthDate, string lpuTypeCode, string lpuName, string baseLpuAddress, Lanit.Emias.RemoteServices.Appointment.PGUServicesInfo.serviceLpuAddress serviceLpuAddress, string externalSystemId) {
this.omsNumber = omsNumber;
this.omsSeries = omsSeries;
this.birthDate = birthDate;
this.lpuTypeCode = lpuTypeCode;
this.lpuName = lpuName;
this.baseLpuAddress = baseLpuAddress;
this.serviceLpuAddress = serviceLpuAddress;
this.externalSystemId = externalSystemId;
}
}
或像这样:
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.18058")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://api.service.soap.emias.lanit.ru/")]
public partial class serviceLpuAddress : baseDto {
private string areaField;
private string districtField;
private string streetField;
private string houseField;
private string buildingField;
private string constructionField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=0)]
public string area {
get {
return this.areaField;
}
set {
this.areaField = value;
this.RaisePropertyChanged("area");
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=1)]
public string district {
get {
return this.districtField;
}
set {
this.districtField = value;
this.RaisePropertyChanged("district");
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=2)]
public string street {
get {
return this.streetField;
}
set {
this.streetField = value;
this.RaisePropertyChanged("street");
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=3)]
public string house {
get {
return this.houseField;
}
set {
this.houseField = value;
this.RaisePropertyChanged("house");
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=4)]
public string building {
get {
return this.buildingField;
}
set {
this.buildingField = value;
this.RaisePropertyChanged("building");
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=5)]
public string construction {
get {
return this.constructionField;
}
set {
this.constructionField = value;
this.RaisePropertyChanged("construction");
}
}
}
我不知道他们为什么不同:(