Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# PostSharp NotifyPropertyChanged属性不适用于自定义设置程序_C#_Wpf_Inotifypropertychanged_Postsharp - Fatal编程技术网

C# PostSharp NotifyPropertyChanged属性不适用于自定义设置程序

C# PostSharp NotifyPropertyChanged属性不适用于自定义设置程序,c#,wpf,inotifypropertychanged,postsharp,C#,Wpf,Inotifypropertychanged,Postsharp,嗨,我已经试了几个星期的PostSharp Express了。NotifyPropertyChanged属性对于默认的getter和setter工作良好,但是一旦我自定义了setter,它就不会工作了。尽管我在调试模式下看到更改的值,但屏幕上没有刷新数据get。下面是我的示例模型类: [NotifyPropertyChanged] public class Question { public string QuestionCode { get; set; } private s

嗨,我已经试了几个星期的PostSharp Express了。NotifyPropertyChanged属性对于默认的getter和setter工作良好,但是一旦我自定义了setter,它就不会工作了。尽管我在调试模式下看到更改的值,但屏幕上没有刷新数据get。下面是我的示例模型类:

[NotifyPropertyChanged]
public class Question
{
    public string QuestionCode { get; set; }

    private string _answer;

    public string Answer
    {
        get { return _answer; }
        set
        {
            if (_answer == value) return;
            _answer = value;
            if (!String.IsNullOrEmpty(_answer) && _answer.ToLower().Equals("no"))
                IsNoChecked = true;
            else if (!String.IsNullOrEmpty(_answer) && _answer.ToLower().Equals("yes"))
                IsYesChecked = true;
            else if (!String.IsNullOrEmpty(_answer) && _answer.ToLower().Equals("n/a"))
                IsNotApplicableChecked = true;

        }
    }
}
绑定对于属性QuestionCode很好

但是在这里,当我在ViewModel中更改Answer属性时,它只在第一次触发更改,除了更改不会传播之外。我已经定好了

UpdateSourceTrigger=PropertyChanged, Mode=TwoWay 
属性到我的控件

更新:我在另一个类中使用上面的类作为列表,如下所示:

[NotifyPropertyChanged]
public class Category
{
    public string CategoryName { get; set; }
    public List<Question> Questions { get; set; }
    public string SubCategory { get; set; }
}
[NotifyPropertyChanged]
公共类类别
{
公共字符串CategoryName{get;set;}
公共列表问题{get;set;}
公共字符串子类别{get;set;}
}

不幸的是,我被迫单独为此属性实现常规的INotifyPropertyChangedEvent事件。PostSharp不支持这种开箱即用的行为吗?还是我在这里遗漏了什么?请提供帮助。

在我们对此类的测试中,始终为Answer属性引发PropertyChanged事件。我们使用最新版本的PostSharp-3.1.64和4.1.13进行了测试。您的项目中使用的是什么版本?出于测试目的,您还可以手动订阅事件,并在每次引发事件时记录属性名称。感谢您的快速响应。我已经更新了我的问题。我使用的是4.1.12.0。实际上,这个“问题”类在另一个名为Category的类中以列表的形式使用,这个类也用这个属性标记。是否有一种特殊的方法来处理列表的属性通知?通常,您需要使用ObservableCollection而不是List来通知集合项的更改。