对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
然后配置菜单:
<sdk:TreeViewItem Header="产品管理" IsExpanded="True">
<controls:AdminMenuItem Id="1" Margin="2" Content="ProductEdit" NavigateView="RapidSL.SL.App.Main.xap/Product.Index" ViewPermission="ProductView"/>
<controls:AdminMenuItem Id="2" Margin="2" Content="CategoryEdit" NavigateView="RapidSL.SL.App.Main.xap/Category.Index" ViewPermission="CategoryView"/>
</sdk:TreeViewItem>
- 1.
- 2.
- 3.
- 4.
XapHost控件提供动态下载.xap及加载
public XapHost(string xapUri, string viewName = null)
{
InitializeComponent();
this.FileName = xapUri;
var xapLoad = new XapLoader(xapUri);
xapLoad.DownloadProgressChanged += (s, e) =>
{
this.TotalSize = (e.TotalBytesToReceive * 1d / 1024 / 1024).ToString("0.00");
this.Percentage = e.ProgressPercentage;
};
xapLoad.LoadCompleted += (s, e) =>
{
this.Content = e.Element;
};
xapLoad.LoadControl(null, viewName);
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
对Resource的支持
找到所有标识有 StaticResourceAttribute的类,然后创建相关实例,并注入到Application.Resources,相当于在 App.xaml里手写资源
实现了资源管理器对资源进行注入管理
View Code
public class ViewModelManager
{
private static Application app = Application.Current;
public static void InjectViewModelsToResources()
{
foreach (AssemblyPart ap in Deployment.Current.Parts)
{
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);
}
}
- 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.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
键盘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.
- 2.
- 3.
具体绑定按钮和键盘事件
#region SubmitButton AttachProperty
public static object GetSubmitButton(DependencyObject obj)
{
return (object)obj.GetValue(SubmitButtonProperty);
}
public static void SetSubmitButton(DependencyObject obj, object value)
{
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
- 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.
原文链接:http://www.cnblogs.com/guozili/archive/2012/08/28/2659035.html
【编辑推荐】