基于Silverlight的快速开发框架RapidSL新特性解析
2012-08-28 08:18
543 查看
对sl传统的开发方式进行了集成和封装,核心模块基于MVVM,通用的CRUD ViewModel,只需要定制自己的Xaml View,提供了非常便捷的快速开发方式; 采用了Silverlight 5.0 + EF4.1 Code First + Ria Service SP2 + Ria Service Toolkit + Silverlight Control Toolkit + Light MVVM;已经实现了轻量级的权限管理,上传模块,内容管理,作为实例,涉及到了sl开发的各种技术难点和技巧,既可以作为学习,也可以作为项目开发的原型
点击预览 | 源代码支持动态加载.xap,面向插件开发
RapidSL.SL.App.Portal提供主框架的UI逻辑,只需要开发自己的App,如RapidSL.SL.App.Main
View Code
1 public class ViewModelManager
2 {
3 private static Application app = Application.Current;
4
5 public static void InjectViewModelsToResources()
6 {
7 foreach (AssemblyPart ap in Deployment.Current.Parts)
8 {
9 var sri = Application.GetResourceStream(new Uri(ap.Source, UriKind.Relative));
var assembly = new AssemblyPart().Load(sri.Stream);
InjectViewModelsToResources(assembly);
}
}
public static void InjectViewModelsToResources(Assembly assembly)
{
foreach (Type type in assembly.GetTypes())
{
var attributes = type.GetCustomAttributes(false);
foreach (var attribute in attributes)
{
if (attribute is StaticResourceAttribute)
{
var resourceKey = ((StaticResourceAttribute)attribute).Key;
if (string.IsNullOrEmpty(resourceKey))
resourceKey = type.Name;
var obj = Activator.CreateInstance(type);
if (!app.Resources.Contains(resourceKey))
app.Resources.Add(resourceKey, obj);
}
}
}
}
public static T GetViewModelFromResources<T>()
{
var key = typeof(T).Name;
if (app.Resources.Contains(key))
return (T)app.Resources[key];
else
return default(T);
}
}
键盘Enter键提交表单
使用AttatchProperty实现传统Html表单的键盘Enter提交
<Grid x:Name="LayoutRoot" core:AttachProperties.SubmitButton="{Binding ElementName=submit}">
<Button x:Name="submit" Content="登录" Margin="20,0,20,0" Padding="20,0,20,0" Command="{Binding UserLogin}"/>
</Grid>
具体绑定按钮和键盘事件
1 #region SubmitButton AttachProperty
2 public static object GetSubmitButton(DependencyObject obj)
3 {
4 return (object)obj.GetValue(SubmitButtonProperty);
5 }
6
7 public static void SetSubmitButton(DependencyObject obj, object value)
8 {
9 obj.SetValue(SubmitButtonProperty, value);
}
// Using a DependencyProperty as the backing store for SubmitButton. This enables animation, styling, binding, etc...
public static readonly DependencyProperty SubmitButtonProperty =
DependencyProperty.RegisterAttached("SubmitButton", typeof(object), typeof(AttachProperties), new PropertyMetadata(SubmitButtonChanged));
private static void SubmitButtonChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var button = (ButtonBase)e.NewValue;
var form = d as UIElement;
form.KeyDown += (s, se) =>
{
if (se.Key == Key.Enter)
{
button.Focus();
if (button.Command != null)
button.Dispatcher.BeginInvoke(()=> button.Command.Execute(null));
}
};
}
#endregion
相关文章推荐
- 基于 Silverlight的快速开发框架RapidSL之MVVM解析
- 基于 Silverlight的快速开发框架RapidSL新版改进源码
- (转)基于Silverlight的快速开发框架RapidSL之开源
- 基于Silverlight的快速开发框架RapidSL之开源
- RDIFramework.NET — 基于.NET的快速信息化系统开发框架 — 系列目录
- [置顶] 基于.NET的快速信息化系统开发框架 — RDIFramework.NET — 系统目录
- 基于MINA框架快速开发网络应用程序
- 基于.Net 2.0 (C# 2.0, ASP.NET 2.0)的快速开发框架设计NBear V1.8.1 [开源]
- iOS快速开发框架Bee-Framework应用和解析(二) --- Bee framework架构概览
- 基于Silverlight的精简框架之解析
- 基于.Net 2.0 (C# 2.0, ASP.NET 2.0)的快速开发框架设计NBear V3.3.9 Stable [开源]
- express(基于 Node.js 平台,快速、开放、极简的 web 开发框架)
- 馒头的基于ORM的快速开发框架
- 基于MINA框架快速开发网络应用程序
- Silverlight企业应用快速开发平台框架设计(一)目标
- 基于MINA框架快速开发网络应用程序
- QuickTV:一款基于AndroidQuick快速开发框架实现的直播APP
- 基于springmvc+mybatis搭建的J2EE快速开发框架
- 基于EF Core的Code First模式的DotNetCore快速开发框架
- 基于MINA框架快速开发网络应用程序