ReactiveUI - this.RaiseAndSetIfChanged

Kop*_*nik 2 c# wpf reactiveui .net-4.5

我通过nuget将最新的ReactiveUI(5.0.2)下载到基于.NET 4.5的项目中.

我用一个属性创建了简单的视图模型类:

using System;
using System.Threading;
using System.Windows;
using ReactiveUI.Xaml;

    namespace ReactiveUI.Study.ViewModels
    {
        public class ShellViewModel : ReactiveObject
        {
            #region Properties

            private string _login;

            public string Login
            {
                get
                {
                    return _login;
                }
                set
                {
                    this.RaiseAndSetIfChanged(x => x.Login, value);
                }
            }

        }
    }
Run Code Online (Sandbox Code Playgroud)

当我尝试编译我的项目时,我得到了异常

Cannot convert lambda expression to type 'ref string' because it is not a delegate type
Run Code Online (Sandbox Code Playgroud)

我刚开始学习我不知道这个问题的根源在哪里,因为我使用来自https://github.com/reactiveui/ReactiveUI.Samples/blob/master/ReactiveUI_4Only.Samples.sln的样本

并且所有项目都基于.NET 4.0,并且还使用旧版本的ReactiveUI.

谢谢

Ari*_*edi 10

更改

this.RaiseAndSetIfChanged(x => x.Login, value);
Run Code Online (Sandbox Code Playgroud)

this.RaiseAndSetIfChanged(ref _login, value);
Run Code Online (Sandbox Code Playgroud)

现在,这是根据发行说明声明属性的唯一方法:

https://github.com/reactiveui/ReactiveUI/blob/master/docs/migrating-from-rxui4.md