警告"方法'add_PropertyChanged'在类型"使用INotifyPropertyChanged [英] Warning "Method 'add_PropertyChanged' in type" with INotifyPropertyChanged

查看:72
本文介绍了警告"方法'add_PropertyChanged'在类型"使用INotifyPropertyChanged的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Community,

Hello Community,

我实现了一个INotifyPropertyChanged( Windows .UI.Xaml.Data)  进入我的ViewModel。在构建时,我收到警告和异常:

i implement a INotifyPropertyChanged (Windows.UI.Xaml.Data) into my ViewModel. On building i get a Warning and Exception:

警告  1 方法'add_PropertyChanged',类型为'GetTextApp.ViewModels.DefaultViewModel',来自程序集'gettextapp.intermediate,Version = 1.0.0.0, Culture = neutral,PublicKeyToken = null'没有实现。  C:\ Users \webmaster \Documents\Visual
Studio 11 \Projects\SendTextApp \ GetTextApp \ MainPage.xaml  ; GetTextApp

Warning 1 Method 'add_PropertyChanged' in type 'GetTextApp.ViewModels.DefaultViewModel' from assembly 'gettextapp.intermediate, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' does not have an implementation. C:\Users\webmaster\Documents\Visual Studio 11\Projects\SendTextApp\GetTextApp\MainPage.xaml GetTextApp

错误  2  XML命名空间中的未知类型'DefaultViewModel'使用:GetTextApp.ViewModels'  C:\ Users \webmaster \Documents\Visual Studio 11 \Projects\SendTextApp \ GetTextApp \ MainPage.xaml  10  10  GetTextApp

Error 2 Unknown type 'DefaultViewModel' in XML namespace 'using:GetTextApp.ViewModels' C:\Users\webmaster\Documents\Visual Studio 11\Projects\SendTextApp\GetTextApp\MainPage.xaml 10 10 GetTextApp



当我删除I​​NotifyPropertyChanged时,代码有效..


When i remove the INotifyPropertyChanged, the code works..

这里的实现:

public class DefaultViewModel : INotifyPropertyChanged
    {
        private string _welcomeText;
        public string WelcomeText 
        {
            get { return _welcomeText; }
            set 
            { 
                _welcomeText = value;

                OnPropertyChanged("WelcomeText");
            }
        }

        public DefaultViewModel()
        {
            if (Windows.ApplicationModel.DesignMode.DesignModeEnabled)
                return;

            App.TextIncoming += text => WelcomeText = "Hello " + text;
        }

        public event PropertyChangedEventHandler PropertyChanged;

        public void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }

谢谢!
b $ b $
BFreakout

Thanks!

BFreakout

推荐答案

您好BFreakout,

Hi BFreakout,

您的代码编译好我。您确定使用的是Windows.UI.Xaml.Data.INotifyPropertyChange而不是System.ComponentModel吗?另见

this previous线程
,虽然它看起来并不直接适用于您提供的代码。

Your code compiles fine for me. Are you sure you are using Windows.UI.Xaml.Data.INotifyPropertyChange and not System.ComponentModel? Also see this previous thread, although it doesn't look directly applicable to the code you provided.

- Rob


这篇关于警告"方法'add_PropertyChanged'在类型"使用INotifyPropertyChanged的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆