在 silverlight 中使用 wcf 服务中的类 - notifypropertychanged 不起作用

发布于 2024-12-11 09:53:25 字数 1090 浏览 0 评论 0原文

我在 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 方法。

我做错了什么? 谢谢

I'm having the following class defined in my wcf service

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));
        }

I want to use IsDirty value to check if the object needs to be saved in the database.

In a silverlight page I have the following lines:

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

My Problem is that after the last line, I was expecting to have IsDirty= true but it is still false. I'm thinking that the Auoturism class that comes from service reference, doesn't have any more the method NotifyPropertyChanged.

What am I doing wrong?
Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一世旳自豪 2024-12-18 09:53:25

如果您使用RIA WCF 服务(我必须从您的问题中假设),那么您的 Autoturism 对象的客户端版本将仅具有来自服务端的属性,但不具有代码班级。

基本上,RIA 服务为客户端创建仅具有相同“形状”(但不具有相同代码)的代理对象。

要完全共享代码和数据,您需要将它们作为 .shared.cs 类。然后完整的源代码将被复制到您的客户项目中。

If you are using RIA WCF services (which I have to assume from your problem), then your Client side version of the Autoturism object will only have the properties, but not the code, from your service-side class.

Basically RIA Services creates proxy objects for the client that have the same "shape" only (but not the code).

To fully share code and data you need to have them as a .shared.cs class. Then the full source will be copied to your client project.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文