簡體   English   中英

在Silverlight中使用WCF服務中的類-notifypropertychanged不起作用

[英]Using class from wcf service in silverlight - notifypropertychanged doesn't work

我在wcf服務中定義了以下類

public class Autoturism : INotifyPropertyChanged
    {
        private int _AutoturismID;
        public int AutoturismID
        { get { return _AutoturismID; } set { _AutoturismID = value; NotifyPropertyChanged("AutoturismID"); } }

        private string _NumarAutoturism;
        public string NumarAutoturism
        { get { return _NumarAutoturism; } set { _NumarAutoturism = value; NotifyPropertyChanged("NumarAutoturism"); } }

        public bool IsDirty { get; set; }

        public event PropertyChangedEventHandler PropertyChanged;
        private void NotifyPropertyChanged(String info)
        {
            IsDirty = true;
            if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs(info));
        }

我想使用IsDirty值檢查對象是否需要保存在數據庫中。

在Silverlight頁面中,我有以下幾行:

AutoCurent = new Autoturism();
AutoCurent.NumarAutoturism="13424";

我的問題是,在最后一行之后,我期望IsDirty = true,但仍為false。 我認為來自服務引用的Auoturism類不再具有NotifyPropertyChanged方法。

我究竟做錯了什么? 謝謝

如果您使用的是RIA WCF服務(我必須從您的問題中假定),則Autoturism對象的客戶端版本將僅具有服務端類的屬性,而沒有代碼。

基本上,RIA Services為客戶端創建僅具有相同“形狀”(而不是代碼)的代理對象。

要完全共享代碼和數據,您需要將它們作為.shared.cs類。 然后,完整的源代碼將被復制到您的客戶項目中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM