微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

基于Silverlight的快速开发框架RapidSL新特性解析

对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

     

  • 然后配置菜单
    1  < sdk:TreeViewItem  Header ="产品管理"  IsExpanded ="True" >
    2                                  controls:AdminMenuItem  Id ="1"  Margin ="2"  Content ="ProductEdit"  NavigateView ="RapidSL.SL.App.Main.xap/Product.Index"  ViewPermission ="ProductView" />
    3                                  ="CategoryEdit" ="RapidSL.SL.App.Main.xap/Category.Index" ="CategoryView" 4                              </ sdk:TreeViewItem >
    NavigateView="RapidSL.SL.App.Main.xap/Product.Index"将调用XapHost控件从服务端下载动态加载

     

    NavigateView="RapidSL.SL.App.Portal.Admin"将调用当前程序集的控件

     

     

  •  XapHost控件提供动态下载.xap及加载

     

    复制代码

     1  public XapHost( string xapUri,  string viewName =  null)
     2         {
     3             InitializeComponent();
     4 
     5              this.FileName = xapUri;
     6 
     7              var xapLoad =  new XapLoader(xapUri);
     8             xapLoad.DownloadProgressChanged += (s, e) =>
     9             {
    10                  this.TotalSize = (e.TotalBytesToReceive * 1d /  1024 /  1024).ToString( " 0.00 ");
    11                  this.Percentage = e.Progresspercentage;
    12             };
    13 
    14             xapLoad.LoadCompleted += (s,128)">15             {
    16                  this.Content = e.Element;
    17             };
    18 
    19             xapLoad.LoadControl( null, viewName);
    20         }

    复制代码

 

对Resource的支持
  • 找到所有标识有 StaticResourceAttribute的类,然后创建相关实例,并注入到Application.Resources,相当于在 App.xaml里手写资源

  • 实现了资源管理器对资源进行注入管理

View Code

键盘Enter键提交表单

    • 使用AttatchProperty实现传统Html表单的键盘Enter提交
      Grid  x:Name ="LayoutRoot"  core:AttachProperties.SubmitButton =" {Binding ElementName=submit} " 2  Button  ="submit" ="登录" ="20,20,0"  Padding  Command {Binding UserLogin} 3  Grid >

 

  • 具体绑定按钮和键盘事件

    复制代码

     1  #region SubmitButton AttachProperty
     2          public  static  object GetSubmitButton(DependencyObject obj)
     3         {
     4              return ( object)obj.GetValue(SubmitButtonProperty);
     5         }
     6 
     7          void SetSubmitButton(DependencyObject obj,  object value)
     8         {
     9             obj.SetValue(SubmitButtonProperty, value);
    10         }
    11 
    12          //  Using a DependencyProperty as the backing store for SubmitButton.  This enables animation, styling, binding, etc...
    13          readonly DependencyProperty SubmitButtonProperty =
    14             DependencyProperty.Registerattached( " SubmitButton ",255)">typeof( object),255)">typeof(AttachProperties),255)">new PropertyMetadata(SubmitButtonChanged));
    15 
    16          private  void SubmitButtonChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    17         {
    18              var button = (ButtonBase)e.NewValue;
    19              var form = d  as UIElement;
    20             form.KeyDown += (s, se) =>
    21             {
    22                  if (se.Key == Key.Enter)
    23                 {
    24                     button.Focus();
    25                      if (button.Command !=  null)
    26                        button.dispatcher.BeginInvoke(()=>  button.Command.Execute( null));
    27                 }
    28             };
    29         }
    30          #endregion

    复制代码

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐