我使用的是VS 2017社区版
我正在创建 MVVM 模式。安装 fody 后,我的代码出现错误,而教程的讲师在 vs 2015 上实现了它
这是代码:
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] 在这一点上不应犯错误,讲师已成功实现它,那么我的代码中是否缺少任何内容?
错误说:
严重性代码 说明 项目文件行抑制状态
错误 CS0619“ImplementPropertyChangedAttribute”已过时:“此
配置选项已被弃用。该属性的使用
是将 INotifyPropertyChanged 添加到具有关联事件的类中
定义。之后所有实现的类
INotifyPropertyChanged 编织了它们的属性,天气它们有
是否 ImplementPropertyChangedAttribute。这个属性经常被
被错误地解释为选择拥有财产的方法
编织,这从来都不是意图,也不是它的运作方式。这
属性已替换为
添加INotifyPropertyChangedInterfaceAttribute。' GProject_MVVM c:\users\ahmed
hussainy\文档\视觉工作室
2017\项目\GProject_MVVM\GProject_MVVM\ViewModel\BaseViewModel.cs 9 活动
异常已经说明了答案。
ImplementPropertyChangedAttribute' 已过时:'此配置
选项已被弃用。该属性的用途是添加
INotifyPropertyChanged 为具有关联事件的类
定义。之后所有实现的类
INotifyPropertyChanged 编织了它们的属性,天气它们有
是否 ImplementPropertyChangedAttribute。
使用新版本的 Fody.PropertyChanged,您不再需要添加该属性。只需制作您想要编织的类即可INotifyPropertyChanged
它会起作用的。
所以基本上只是删除/删除[ImplementPropertyChanged]
它将编译并编织(如果编织器存在于FodyWeavers.xml
)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)