随笔 - 31  文章 - 0  评论 - 1134  阅读 - 39万

基于 Silverlight的快速开发框架RapidSL之MVVM解析

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

posted on   guozili  阅读(2300)  评论(3编辑  收藏  举报
编辑推荐:
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
阅读排行:
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
历史上的今天:
2010-06-03 基于 Silverlight的精简框架之版本和控件更新
< 2011年6月 >
29 30 31 1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 1 2
3 4 5 6 7 8 9

点击右上角即可分享
微信分享提示