班级已经注册" 只是试图探究这个非常烦人的错误的根源.请注意,DataService中的内容并不重要,即使只有一个空函数的接口和服务也会产生相同的错误解决方案由于某种原因,混合可能会多次初始化ViewModelLocator.所以您需要添加支票:if (!SimpleIoc.Default.IsRegistered<ISomeService>()) SimpleIoc.Default.Register<ISomeService, SomeService>();I've been using MVVMLight for some time now and started using V4 since it was first made available.However one issue has always persisted with me which I've been unable to solve.If I create a project using the MVVM 4 project template the solution builds fine, runs fine and works ok in blend.HoweverIf I start my own project and install MVVMLight V4 using Nuget, as soon as I add even a basic DataService and enable the commented out code in the ViewModelLocator template and open up the project in Blend I just get an error:"Class is already registered"Just trying to get to the bottom of this very annoying error.Just to be clear it doesn't matter what is in the DataService as even with an interface and service with only 1 empty function gives the same error 解决方案 Blend, for some reason, may initialize the ViewModelLocator more than once.So you need to add a check:if (!SimpleIoc.Default.IsRegistered<ISomeService>()) SimpleIoc.Default.Register<ISomeService, SomeService>(); 这篇关于&lt;接口&gt;使用MVVMLightV4在混合中已注册错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
11-02 10:21