我的WPF项目中有MVVM Light和MvvmDialogs。
如果我在ViewModelLocator的构造函数中有此行
HttpPost httppost = new HttpPost("https://box.one.th/app/api/upload ");
我在此行的App.xaml中收到此警告。设计器没有绑定,但是应用程序可以正常运行。
SimpleIoc.Default.Register<IDialogService>(() => new DialogService(null, new DialogTypeLocator(), null));
已经有一家工厂注册了MvvmDialogs.IDialogService。
如果在设计模式下禁用该行,则会出现此错误。
找到的程序集的清单定义与程序集引用不匹配。
我在做什么错了?
编辑:这些似乎是2个完全独立的问题。我删除了MvvmDialogs,仍然出现第二个错误。
在进一步研究中,在ViewModelLocator构造函数中使用ViewModelBase.IsInDesignModeStatic会引发第二个错误,而在设计模式下注册DialogService会引发第一个错误-但是我需要ViewModelBase.IsInDesignModeStatic才能在设计模式下将其禁用...
答案 0 :(得分:2)
我找到了这个帖子 SimpleIoc.Default.Register fails at IsInDesignModeStatic if the Interface is in different assembly
我通过向DialogService注册解决了第一个问题
if (!SimpleIoc.Default.IsRegistered<IDialogService>())
SimpleIoc.Default.Register<IDialogService>(() => new DialogService(null, new DialogTypeLocator(), null));
我通过不使用ViewModelBase.IsInDesignModeStatic“解决了”第二个问题-这并不是真正的解决方案,但至少现在该错误已消失。很想知道如何设置ViewModel的设计时模拟。
编辑:问题#1的更好解决方案是在构造函数的开头添加
SimpleIoc.Default.Reset();
问题2的更好解决方案是使用它而不是ViewModelBase.IsInDesignModeStatic
DesignerProperties.GetIsInDesignMode(new DependencyObject())