1

プログラムでフィールドをコントロールにバインドしようとしていますが、次のようなものを生成しています:

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