zoukankan      html  css  js  c++  java
  • AvalonDock 2.0+Caliburn.Micro+MahApps.Metro实现Metro风格插件式系统(二)

    上次已经建立了可运行的基本框架,这篇就说说怎么把我们自定义的View自动加载并添加到AvalonDock里面,AvalonDock里有3种类型的UI部件,Document, DockableContent以及Floting类型,我主要说一下Document,DockableContent的添加,在AvalonDock里Document类型可参考VS,DockableContent相当于VS里的工具栏等,之后我直接在.cs文件里写注释以及解析。

    现在的项目结构:

    运行结果:

      

      可以看到里面多了一个测试的Document,该Document是由MEF自动加载并且绑定到AvalonDock里,这里我只写一个一个Document,有兴趣的可以自己动手试一试,目前的Document是写在主程序里面,其实这Document应该写在一个单独的DLL里面,这就是我们所谓的插件。 [BY Zengg]

    DockScreenManager类  

     DockScreenManager

    DocumentBase类

     DocumentBase

    IDockScreen接口

     IDockScreen

    IDocument接口

     IDocument

    PanesStyleSelector类

    复制代码
     1  /// <summary>
     2     /// 这个很重要,这是为使AvalonDock能区别Document和DockableContent类型并返回不同的style,两个类型不同style有不同的绑定属性
     3     /// 所以要区分开来
     4     /// </summary>
     5     public class PanesStyleSelector : StyleSelector
     6     {
     7         public Style ToolStyle
     8         {
     9             get;
    10             set;
    11         }
    12 
    13         public Style DocumentStyle
    14         {
    15             get;
    16             set;
    17         }
    18         /// <summary>
    19         /// 区别逻辑在这里写
    20         /// </summary>
    21         /// <param name="item">实现了IDocument或IDockableContent接口的实例</param>
    22         /// <param name="container"></param>
    23         /// <returns></returns>
    24         public override Style SelectStyle(object item, DependencyObject container)
    25         {
    26             IDockScreen obj = (IDockScreen)item;
    27             
    28             if (item != null)
    29             {
    30                 //判定为什么类型
    31                 if (item is IDocument)
    32                 {
    33                     return DocumentStyle;
    34                 }
    35                 else
    36                 {
    37                     return ToolStyle;
    38                 }
    39             }
    40          
    41             return base.SelectStyle(item, container);
    42         }
    43     }
    复制代码

    较第一张更改部分:

      DockViewModel类

    复制代码
     1 namespace DemoApplication.Views
     2 {
     3     /// <summary>
     4     /// 字符串"DockViewModel"是为了标记唯一性,在ShellViewModel里导入时也要指定为"DockViewModel",这相当于一个key
     5     /// </summary>
     6     [Export("DockViewModel", typeof(IDockScreenManager))]
     7     public class DockViewModel : DockScreenManager
     8     {
     9         public DockViewModel()
    10             : base()
    11         {
    12 
    13         }
    14     }
    15 }
    复制代码

    ShellViewModel类

    复制代码
     1 namespace DemoApplication
     2 {
     3     [Export(typeof(IShell))]
     4     class ShellViewModel : IShell
     5     {
     6         readonly IWindowManager windowManager;
     7         [ImportingConstructor]
     8         public ShellViewModel(IWindowManager windowManager)
     9         {
    10             this.windowManager = windowManager;
    11 
    12         }
    13         /// <summary>
    14         /// DockView
    15         /// </summary>
    16         [Import("DockViewModel")]
    17         public IDockScreenManager DockContent { get; set; }
    18     }
    19 }
    复制代码

    MefBootstrapper类

     MefBootstrapper

    AvalonDock还支持其他几种皮肤,可以满足大众的需求:

    AeroTheme

     ExpressionLightTheme

    ExpressionDarkTheme

    VS2010Theme

       DockableContent类型的实现和Document实现是一样的,只是实现的接口不同,DockableContent实现的是IDockableContent接口,具体请参考Document实现,有疑问的可以提出来,尽量帮助解决,解释写得略简单不好意思,但是有源码参考,如果源码对大家有帮助的话,求个推荐,回复或粉的神马的都好。。。

    源码地址:

    http://pan.baidu.com/share/link?shareid=819683340&uk=554439928

    如果您看了本篇博客,觉得对您有所收获,请点击右下角的 [推荐]

    如果您想转载本博客,请注明出处

    如果您对本文有意见或者建议,欢迎留言

    感谢您的阅读,请关注我的后续博客

    作者:Zengg 出处:http://www.cnblogs.com/01codeworld/

    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

  • 相关阅读:
    Windows中目录及文件路径太长无法删除的解决方法
    html5--移动端视频video的android兼容,去除播放控件、全屏等
    npm scripts 使用指南
    如何在 React Native 中写一个自定义模块
    流媒体测试笔记记录之————解决问题video.js 播放m3u8格式的文件,根据官方的文档添加videojs-contrib-hls也不行的原因解决了
    React.js 小书
    React.js 应用 UI 框架
    npm配置文件
    Linux 普通进程 后台进程 守护进程
    Linux下passwd和shadow文件内容详解
  • 原文地址:https://www.cnblogs.com/magic-xxj/p/10723897.html
Copyright © 2011-2022 走看看