Silverlight中通过WCF方式传递数据 修改服务器端类的属性Silverlight中无法显示该属性...

引言

在B/S开发中客户端常用到Silverlight,为了使前、后台能够共享类,采用WCF方式从后台传递数据至前台。当在Silverlight中通过DataGrid绑定显示数据时,需要为DataGrid指定从服务器端获取的数据源,同时还要为DataGrid对应的Column指定对应的字段。当修改服务器端类的属性后,会出现前台绑定的字段无法显示的问题。

问题的分析

在Silverlight中如何通过WCF方式从后台传递数据至前台,并在前、后台共享类请参考

http://www.cnblogs.com/jv9/archive/2009/12/04/1616667.html

针对修改服务器端类中属性,前台对应字段无法显示问题,单步执行程序至为DataGrid指定数据源处,发现数据源中类的属性仍旧是修改前的属性。继续跟踪,程序出现错误并跳转至reference.cs文件中。

实际上,Silverlight为每一个WCF服务都创建了一个reference.cs类,该类中包含了WCF服务与Silverlight的交互信息,并且在该类中为每一个在当前WCF服务中引用的类创建相应的转换类,类的对应信息如下:

服务器端类

public class RescueEquipInfo

{

   public string   str_Name { get; set;   }

        public   string str_MeasureUnit { get; set; }

        public   string str_Model { get;   set; }

        public   string str_Type { get;   set; }

        public   double d_Count { get;   set; }

        public   string str_Unit { get;   set; }

    }

         Reference.cs中对应的类描述:

[System.Diagnostics.DebuggerStepThroughAttribute()]    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization",   "4.0.0.0")]    [System.Runtime.Serialization.DataContractAttribute(Name="RescueEquipInfo", Namespace="http://schemas.datacontract.org/2004/07/AHKY.Model.Entities")]

    public partial class RescueEquipInfo : object,   System.ComponentModel.INotifyPropertyChanged   {

        private   double d_CountField;

        private   string str_MeasureUnitField;

        private   string str_ModelField;

        private   string str_NameField;

        private   string str_TypeField;

        private   string str_UnitField;

        [System.Runtime.Serialization.DataMemberAttribute()]

        public   double d_Count {

            get   {

                return   this.d_CountField;

            }

            set   {

                if   ((this.d_CountField.Equals(value) != true)) {

                    this.d_CountField   = value;

                    this.RaisePropertyChanged("d_Count");

                }

            }

        }

       

        [System.Runtime.Serialization.DataMemberAttribute()]

        public   string str_MeasureUnit {

            get   {

                return   this.str_MeasureUnitField;

            }

            set   {

                if   ((object.ReferenceEquals(this.str_MeasureUnitField, value)   != true)) {

                    this.str_MeasureUnitField   = value;

                    this.RaisePropertyChanged("str_MeasureUnit");

                }

            }

        }

       

        [System.Runtime.Serialization.DataMemberAttribute()]

        public   string str_Model {

            get   {

                return   this.str_ModelField;

            }

            set   {

                if   ((object.ReferenceEquals(this.str_ModelField, value)   != true)) {

                    this.str_ModelField   = value;

                    this.RaisePropertyChanged("str_Model");

                }

            }

        }

       

        [System.Runtime.Serialization.DataMemberAttribute()]

        public   string str_Name {

            get   {

                return   this.str_NameField;

            }

            set   {

                if   ((object.ReferenceEquals(this.str_NameField, value)   != true)) {

                    this.str_NameField   = value;

                    this.RaisePropertyChanged("str_Name");

                }

            }

        }

       

        [System.Runtime.Serialization.DataMemberAttribute()]

        public   string str_Type {

            get   {

                return   this.str_TypeField;

            }

            set   {

                if   ((object.ReferenceEquals(this.str_TypeField, value)   != true)) {

                    this.str_TypeField   = value;

                    this.RaisePropertyChanged("str_Type");

                }

            }

        }

       

        [System.Runtime.Serialization.DataMemberAttribute()]

        public   string str_Unit {

            get   {

                return   this.str_UnitField;

            }

            set   {

                if   ((object.ReferenceEquals(this.str_UnitField, value)   != true)) {

                    this.str_UnitField   = value;

                    this.RaisePropertyChanged("str_Unit");

                }

            }

        }

        

        public   event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;

       

        protected   void RaisePropertyChanged(string propertyName) {

            System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;

            if   ((propertyChanged != null)) {

                propertyChanged(this, new   System.ComponentModel.PropertyChangedEventArgs(propertyName));

            }

        }

    }

 

       当修改服务器端类的属性后,在reference.cs类中,相应属性的对应关系没有得到更新,仍旧对应的修改前的属性名称。为解决本问题,需要将reference.cs中对应关系的属性名称修改为服务器端修改后的属性名称。

 

转载于:https://www.cnblogs.com/gis-dolphin/archive/2013/04/08/3007113.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值