1

我刚刚开始探索 ReactiveUI,但遇到了一些问题。

在 ReactiveObject 中,我尝试基于属性创建一个 observable ......

public class StudentListViewModel : ReactiveObject, IStudentListViewModel
{
    public StudentListViewModel()
    {
        var observable = this.ObservableForProperty(x => x.SearchQuery);
    }

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

...导致以下错误:

找不到 MyApplication.ViewModels.StudentListViewModel 的 ICreatesObservableForProperty。这绝不应该发生,您的服务定位器可能已损坏。

我已将其用作NinjectDI 容器,并尝试像这样告诉 ReactiveUI:

class Bootstrapper : IBootstrapper
{
    public Bootstrapper()
    {
        Kernel = new StandardKernel();
        Kernel.Bind<IBootstrapper>().ToConstant(this);
        Kernel.Bind<IScreen>().ToConstant(this);
        Kernel.Bind<IViewFor<StudentListViewModel>>().To<StudentListView>();

        Router = new RoutingState();

        RxApp.ConfigureServiceLocator(
            (type, key) => Kernel.Get(type, key),
            (type, key) => Kernel.GetAll(type, key),
            (from, type, key) =>
                {
                    var binding = Kernel.Bind(from).To(type);
                    if (key != null)
                        binding.Named(key);
                }
            );
    }
}

有人看到这里的问题吗?

4

1 回答 1

1

您切换了“从”和“键”:

    RxApp.ConfigureServiceLocator(
        (type, key) => Kernel.Get(type, key),
        (type, key) => Kernel.GetAll(type, key),
        (from, type, key) =>
            {
                var binding = Kernel.Bind(type /*this was from*/).To(from /*ditto*/);
                if (key != null)
                    binding.Named(key);
            }
        );
于 2012-09-12T05:32:47.073 回答