1

我正在尝试将字段绑定到控件,我正在像这样生成 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");
        }
    }
}

我不知道他们为什么不同:(

4

2 回答 2

1

确定没有属性吗?因为私有字段不会很有用;Web 引用(无论是基于 wsdl 还是基于 svcutil)通常会添加属性。

但是,如果它真的没有,那么既然它是一个partial class:你仍然可以: 在第二个代码文件中,在正确的命名空间中:

namespace Get.This.Right
{
    partial class appointmentReceptionToDoctor {
        public string DoctorSpecialityCode {
            get { return doctorSpecialityCodeField; }
            set { doctorSpecialityCodeField = value; }
        }

        // etc
    }
}

然而,坦率地说,我发现生成的类型没有属性而只有私有字段非常奇怪——它实际上是不可用的。事实上,INotifyPropertyChanged如果它还没有属性,(它实现的)似乎毫无意义。您确定生成的代码中还没有DoctorSpecialityand吗?DoctorSpecialityCode

于 2013-09-02T10:51:55.613 回答
0

解决此问题的常规方法是创建一个“包装器”类来包装您生成的类,或者只创建一个具有相同属性额外所需属性的普通类。然后您只需要遍历任何集合您可能拥有并将生成的类实例中的值复制到新的类实例中。

于 2013-09-02T10:50:56.070 回答