WCF服务呼叫和MVVM轻工具包出现问题 [英] WCF service call and MVVM light toolkit trouble

查看:96
本文介绍了WCF服务呼叫和MVVM轻工具包出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经构建了一个WCF模板服务,该服务与连接到数据库的EF进行对话(原始:讨论).然后,我的主要目的是一个简单的WPF实现MVVM光. 我的主要应用程序正在引用我的WCF服务,并已自动创建配置文件.

I have build a WCF template service which talks (original: discuss) with my EF connected to my database. Then I have my main aplication which a simple WPF implementing MVVM light. My main application is referecing my WCF service and has created the config file automatically.

在ViewModel构造函数中,我正在调用WCF服务以获取将被绑定到视图的数据的集合.

In my ViewModel constructor I am calling my WCF service in order to get the collecton of data which will be bound to the view.

这样做是麻烦的,初始化到ViewModelLocator.MainStatic的Datacontext生成错误无法创建"ViewModelLocator的实例".

Toruble is that doing that, the Datacontext which is initialised to the ViewModelLocator.MainStatic is generating an error "Cannot create instance of "ViewModelLocator".

如果我从视图模型中删除了服务调用,则会错误地发出错误消息,但无法获取数据.

If I remove the service call from the viewmodel, error desapperas but could not get data of course.

任何想法如何实现服务调用以便在MVVM照明工具套件中填充集合? 您需要检查的任何样品吗?

Any idea how to implement service call in order to populate collection in a MVVM light tool kit ? Any sample you have to go throuh ?

不幸的是,周围没有这样的例子. 并且可以得到它

Unfortunatly there is no such exemple around. and could get it

感谢您的帮助 serge

Thanks for you help serge

推荐答案

通常,我认为这是因为您在设计时进行了调用.在视图模型中使用IsInDesignModeStatic区分运行时代码和设计时间代码.在设计时代码中,我将手动添加一些数据,以使您更轻松地设计视图. 另请参见此讨论以获取更多指导.

In general I would assume that it is because you making the call at design time. Use the IsInDesignModeStatic in your view model to distinguish run time code and design time code. In the designtime code I would add some data manually to make it easier for yo to design your view.. See also this discussion for further guidance.

丹尼尔的答案示例.

这篇文章在设计模式下调用数据库的观点也不起作用.

And this post the point that calls to Databases don't work either in design mode.

修改

Laurent还在关于

Laurent also is bloging about this topic.

这篇关于WCF服务呼叫和MVVM轻工具包出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆