MVVMcross从4升级到6.2.1出现错误Mvx不包含Close Trace Error,警告等的定义

时间:2018-10-29 12:26:47

标签: mvvmcross

在mvvmcross 6.2.1上升级后出现错误Mvx不包含定义      痕迹,警告,错误等

1 个答案:

答案 0 :(得分:2)

自Mvx 4起,发生了很多变化。您应该阅读documentationblogs和迁移指南(from 4 to 5from 5 to 6)。

关于跟踪,警告,错误,现在Mvx提供了一种Diagnostic & Logging的新方法。您必须注入/解析IMvxLog,然后您才能使用所有方法进行跟踪,警告,错误等。

public class MyViewModel : MvxViewModel
{
    private readonly IMvxLog _log;
    public MyViewModel(IMvxLog log)
    {
        _log = log;
    }

    private void SomeMethod()
    {
        _log.Trace("Some message");
    }
}

要关闭视图模型,您需要使用新的Navigation系统:

public class MyViewModel : MvxViewModel
{
    private readonly IMvxNavigationService _navigationService;
    public MyViewModel(IMvxNavigationService navigation)
    {
        _navigationService = navigationService;
    }

    public override void Prepare()
    {
        // first callback. Initialize parameter-agnostic stuff here
    }

    public override async Task Initialize()
    {
        await base.Initialize();

        // do the heavy work here
    }

    public async Task SomeMethod()
    {
        var result = await _navigationService.Navigate<NextViewModel, MyObject, MyReturnObject>(new MyObject());
        //Do something with the result MyReturnObject that you get back
    }
}

public class NextViewModel : MvxViewModel<MyObject, MyReturnObject>
{
    private readonly IMvxNavigationService _navigationService;

    private MyObject _myObject;

    public MyViewModel(IMvxNavigationService navigation)
    {
        _navigationService = navigationService;
    }

    public override void Prepare()
    {
        // first callback. Initialize parameter-agnostic stuff here
    }

    public override void Prepare(MyObject parameter)
    {
        // receive and store the parameter here
        _myObject = parameter;
    }

    public override async Task Initialize()
    {
        //Do heavy work and data loading here
    }

    public async Task SomeMethodToClose()
    {
        await _navigationService.Close(this, new MyReturnObject());
    }
}

如果您不希望返回任何内容,则只需执行_navigationService.Close(this)(当然,您必须删除MyReturnObject的泛型类型参数)就可以了。

HIH