RapidSL框架基于WCF RIAService + EF + MVVM,UI 采用了DomainService + RiaControls + EasySL Controls,对sl传统的开发方式进行了集成和封装,核心模块基于View,ViewModel模型,基本上只需要修改View视图就可以完成 CRUD操作,提供了非常便捷的快速开发方式;
一. Model(Domain Model)
1. RIA Service端通过EF生成
2. 然后在sl项目选中“WCF RIA Services link”,
3. 会自动生成UI Model,省去了DTO,保存在Generated_Code
二. ViewModel
1. 使用了LightMVVM,继承自ViewModelBase
2. 作为前端绑定的业务实体如:
protected bool isShowDataFormPanel; public virtual bool IsShowDataFormPanel { get { return isShowDataFormPanel; } set { isShowDataFormPanel = value; RaisePropertyChanged( " IsShowDataFormPanel " ); } }
3. 作为视图绑定事件通知的RelayCommand
protected ICommand itemEdit; public virtual ICommand ItemEdit { get { if (itemEdit == null ) itemEdit = new RelayCommand(() => { this .IsShowDataFormPanel = true ; }); return itemEdit; } }
4.注入ViewModel到App资源,[StaticResource(Key..., 和在App.xaml里写资源是一样的
namespace RapidSL.UI.ViewModels { [StaticResource( " MainViewModel " )] public partial class MainViewModel : MyViewModelBase
5. 我实现了一个通用的带CRUD ViewModel:
三. View
1. 赋DataContext为对应的ViewModel
< UserControl.DataContext > < Binding Source = " {StaticResource Article_ItemViewModel} " /> </ UserControl.DataContext >
2. Binding和Command
< Button Command = " {Binding ItemDelete} " IsShow = " {Binding IsShowDataFormPanel, Mode=TwoWay} " >
下载:http://easysl.codeplex.com/releases/view/26522
预览:http://rapidsl.guozili.25u.com/ (guest/guest admin/admin 请不要删除资料)
RapidSL - a efficient and fast Infrastructure for silverlight development Produced by xiaoyi / www.guozili. 25u .com / guozili@ 163 .com