如何使用MVVM-Light和WCF RIA服务进行可混合项目 [英] How to have a blendable project using MVVM-Light and WCF RIA Services

查看:60
本文介绍了如何使用MVVM-Light和WCF RIA服务进行可混合项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用MVVM模式构建业务应用程序.我选择MVVM-Light,因为它可以满足我的需求. 在我看到的有关MVVM-Light的每个示例中,没有人使用WCF RIA.经典的MIX10示例在同一项目中使用服务,而WCF RIA在Web项目中创建服务. 问题是:看起来很难建立WCF Ria创建的整个DomainContex的接口(这对我来说确实很困难!),但是如果没有接口,我该如何构建一个伪造的DomainContex以便在Blend和测试中使用? 我想念什么吗? 谢谢.

I'd like to build my business application using the MVVM pattern. I choose MVVM-Light because it fits to my needs. In every example I've seen about MVVM-Light, no-one use the WCF RIA. The classic MIX10 example uses a Service in the same project while WCF RIA create a service in the Web project. The question is: it looks very hard to build an interface of the whole DomainContex the WCF Ria creates (it is surely hard for me!) but without an interface how could I build a fake DomainContex to be used in Blend and in tests as well? Am I missing something? Thanks.

推荐答案

实际上,我使用的解决方案是可混合的,并且使混合过程更加简单.

Actually, the solution I am using is blendable, and makes the blending process even simpler.

以下是我如何使用此框架完成此操作的示例:

Here is an exmample of how I accomplish this using this framework:

 public class FolderViewModel : VMBase
{
    private string _subject = string.Empty;
    private string _folderName = string.Empty;
    private string _service = string.Empty;
    private string _dept = string.Empty;
    private string _efolderid = string.Empty;
    private string _timingName = string.Empty;
    private WorkplanBase _planBase = null;
    private IEnumerable<PSCustomList> _timingOptions = null;
    private decimal _totalvalue = 0;


    public FolderViewModel()
    {
        registerForMessages();

        if (IsInDesignMode)
        {
            // Code runs in Blend --> create design time data.
            EFOLDERID = "0123456790123456790123456791";
            Subject = "9999-00 - This is a test nVision Subject";
            Service = "AUDCOMP";
            Department = "AUDIT";
            FolderName = "NVSN003000";


            List<PSCustomList> listItems = new List<PSCustomList>();
            listItems.Add(new PSCustomList()
            {
                ID = "1234",
                ParameterValue = "Busy Season"
            });
            listItems.Add(new PSCustomList()
            {
                ID = "1134",
                ParameterValue = "Another Season"
            });

            _timingOptions = listItems.ToArray();
            _totalvalue = 12000;

            PlanBase = new WorkplanBase()
            {
                ClientFee = 15000,
                Timing = "1234"
            };
        }
    }
}

然后,所有示例数据都是在ViewModelLocator类中绑定的Acutal View模型的构造函数中定义的.混合时,VMBase可以避免尝试实例化DataContext.

Then all the sample data is defined in the constructor of the Acutal View Models that are bound in your ViewModelLocator class. The VMBase takes care of not trying to instantiate the DataContext when you are in blend.

这篇关于如何使用MVVM-Light和WCF RIA服务进行可混合项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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