本文介绍了使用Fody [ImplementPropertyChanged]时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用VS 2017社区版我正在创建MVVM模式.安装完fody之后,我的代码出现错误,而本教程的讲师在vs 2015上实现了该错误这是代码:

I am Using VS 2017 Community EditionI am creating MVVM pattern. After i installed fody i got error on my code while the instructor of the tutorial implemented it on vs 2015here is the code:

using PropertyChanged;
using System.ComponentModel;

namespace GProject_MVVM.ViewModel
{
    /// <summary>
    /// A base view model that fires Property Changed events as needed
    /// </summary>
    [ImplementPropertyChanged] // **I got error here**
    public class BaseViewModel : INotifyPropertyChanged
    {
        /// <summary>
        /// The event that is fired when any child property changes its value
        /// </summary>
        public event PropertyChangedEventHandler PropertyChanged = (sender, e) => { };
        /// <summary>
        /// Call this to fire <see cref="PropertyChanged"/> event
        /// </summary>
        /// <param name="name"></param>
        public void OnPropertyChanged(string name)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(name));

        }
    }
}

[ImplementPropertyChanged]不应在这一点上出错,因为讲师已成功实现了它,所以我的代码中是否还缺少任何内容?错误提示:

[ImplementPropertyChanged] should not make error on this point the instructor implemented it successfully so is thier anything missing on my code ? The error says:

推荐答案

该异常已经说明了答案.

The exception already states the answer.

使用新版本的Fody.PropertyChanged,您不再需要添加属性.只需将要编织的类实现为INotifyPropertyChanged,它将起作用.

With the new version of Fody.PropertyChanged you don't need to add the attribute any longer. Just make that class you want to be weaved implement INotifyPropertyChanged and it will work.

因此,基本上只需删除/删除[ImplementPropertyChanged] ,它将进行编译和编织(如果编织器存在于FodyWeavers.xml中)

So basically just remove / delete [ImplementPropertyChanged] and it will compile and weave (if the weaver is present in FodyWeavers.xml)

这篇关于使用Fody [ImplementPropertyChanged]时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 23:27