The realization of Metro style plug-in system AvalonDock 2.0+Caliburn.Micro+MahA

Recommended for you: Get network issues from WhatsUp Gold. Not end users.

  The last time we have established basic framework can be run, This article is about how to put our custom View automatic loading and added to the AvalonDock., There are 3 parts of UI type of AvalonDock., Document, DockableContent and Floting type, I mainly talk about Document, the addition of DockableContent, The Document type can refer to VS in AvalonDock, DockableContent is equivalent to VS in the toolbar., After I directly in the.Cs file to write comments and analysis.

The structure of the project now:

The operation results:

  

  It can be seen more than a test of the Document, the Document is composed of MEF automatic loading and binding to AvalonDock, here I only write a Document, are interested can try it yourself, the current Document is written in the main program, the Document should be written in a separate DLL this is what we call the plugin,. [BY Zengg]

The DockScreenManager class  

 1 namespace UICoreFramework
 2 {
 3     /*The inside of the DemoApplication DockViewModel to implement this interface, in order to make all of the Documents and DockableContents centralized management */
 4     public interface IDockScreenManager
 5     {
 6         //And bind to the Document type of data source AvalonDock
 7         ObservableCollection<IDocument> Documents { get; }
 8         //And bind to the Document type of data source AvalonDock
 9         ObservableCollection<IDockableContent> DockableContents { get; }
10     }
11     public class DockScreenManager : ViewAware, IDockScreenManager
12     {
13         /// <summary>
14         /// ImportMany is knowledge of MEF, his role is to put all the implementation of an interface, and marked as Export class pour into, 
15         /// Equivalent to help us automatically instantiated and added to the List collection.
16         /// 
17         /// </summary>
18         [ImportMany]
19         public ObservableCollection<IDocument> Documents { get; set; }
20         [ImportMany]
21         public ObservableCollection<IDockableContent> DockableContents { get; set; }
22         public DockScreenManager()
23         {
24             
25         }
26     }
27 }

DockScreenManager

The DocumentBase class

 1   /// <summary>
 2     /// Abstract class Document, some abstract operation can write inside, in order to facilitate I didn't write anything
 3     /// DemoApplication DocTestViewModel is the inheritance and the abstract class
 4     /// </summary>
 5     public abstract class DocumentBase : IDocument
 6     {
 7 
 8 
 9         public DockType Type
10         {
11             get
12             {
13                 throw new NotImplementedException();
14             }
15             set
16             {
17                 throw new NotImplementedException();
18             }
19         }
20 
21         public DockSide Side
22         {
23             get
24             {
25                 throw new NotImplementedException();
26             }
27             set
28             {
29                 throw new NotImplementedException();
30             }
31         }
32 
33 
34         public string DisplayName
35         {
36             get
37             {
38                 return "Test interface";
39             }
40             set
41             {
42                 throw new NotImplementedException();
43             }
44         }
45 
46         public bool IsNotifying
47         {
48             get
49             {
50                 throw new NotImplementedException();
51             }
52             set
53             {
54                 throw new NotImplementedException();
55             }
56         }
57 
58         public void NotifyOfPropertyChange(string propertyName)
59         {
60             throw new NotImplementedException();
61         }
62 
63         public void Refresh()
64         {
65             throw new NotImplementedException();
66         }
67 
68         public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
69     }

DocumentBase

The IDockScreen interface

 1 namespace UICoreFramework
 2 {
 3     /// <summary>
 4     /// Only the DockableContent type position statement
 5     /// </summary>
 6     public enum DockSide
 7     {
 8         Left,
 9         Top,
10         Right,
11         Bottom
12     }
13     /// <summary>
14     /// The type of Dock
15     /// </summary>
16     public enum DockType
17     {
18         Document,
19         DockableContent,
20     }
21     /// <summary>
22     /// Abstract the basic Content types, and attributes that implement the notification interface, because after binding to AvalonDock is a two-way binding, so we want to AvalonDock operation
23     /// You can directly operate the properties of the interface, such as the DisplayName attribute is used to bind to the AvalonDock LayoutItem Title
24     /// </summary>
25     public interface IDockScreen:INotifyPropertyChangedEx
26     {
27         DockType Type { get; set; }
28         DockSide Side { get; set; }
29         string DisplayName { get; set; }
30     }
31 }

IDockScreen

The IDocument interface

1 /// <summary>
2     /// Abstract the Document interface, not to write something practical
3     /// </summary>
4     public interface IDocument : IDockScreen
5     {
6         
7     }

IDocument

The PanesStyleSelector class

 1  /// <summary>
 2     /// This is very important, this is to return a different style to make AvalonDock difference between Document and DockableContent type and two type, different style have different binding properties
 3     /// So to distinguish
 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         /// The difference between logical write here
20         /// </summary>
21         /// <param name="item">The examples of IDocument or IDockableContent interface.</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                 //Determine what type of
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     }

The first part is changed:

  The DockViewModel class

 1 namespace DemoApplication.Views
 2 {
 3     /// <summary>
 4     /// The string "DockViewModel" to mark the uniqueness, introduced in ShellViewModel may also be designated as "DockViewModel", which is equivalent to a key
 5     /// </summary>
 6     [Export("DockViewModel", typeof(IDockScreenManager))]
 7     public class DockViewModel : DockScreenManager
 8     {
 9         public DockViewModel()
10             : base()
11         {
12 
13         }
14     }
15 }

The ShellViewModel class

 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 }

The MefBootstrapper class

 1  protected override void Configure()
 2         {
 3             /*The CompositionContainer object has two main uses in applications. First, it keeps track of which parts can be used in combination, their dependencies, and serves as the context for any given composition. Secondly, it provides the application can start the combination method, case retrieval component, dependency or filling component. 
 4             Components can be directly used for container, or by the Catalog attribute for container. All components can be found in this ComposablePartCatalog can be used to meet the import container, also includes any components added directly. */ 
 5             //container = new CompositionContainer(
 6             //    new AggregateCatalog(AssemblySource.Instance.Select(x => new AssemblyCatalog(x)))
 7             //    );
 8 
 9             
10             var catalog = new AggregateCatalog(
11                AssemblySource.Instance.Select(x => new AssemblyCatalog(x)).OfType<ComposablePartCatalog>()
12                );
13 
14             container = new CompositionContainer(catalog);
15 
16             var batch = new CompositionBatch();
17             var dockScreenManage = new DockScreenManager();
18             batch.AddExportedValue<IWindowManager>(new WindowManager());//The specified CompositionBatch object is added to the
19             batch.AddExportedValue<IEventAggregator>(new EventAggregator());
20             batch.AddExportedValue<IDockScreenManager>(dockScreenManage);
21             batch.AddExportedValue(container);
22             batch.AddExportedValue(catalog);
23             container.Compose(batch);//Execution of portfolio on the container, including changes to the specified in CompositionBatch
24 
25             container.ComposeParts(container.GetExportedValue<IDockScreenManager>());//Because there are marked as Import field in DockScreenManager, so in the MEF container assembling the parts into the specified
26         }

MefBootstrapper

AvalonDock also supports several other skin, can meet the needs of the public:

AeroTheme

 ExpressionLightTheme

ExpressionDarkTheme

VS2010Theme

   And Document DockableContent type of implementation is the same, only the interface is different, DockableContent is the realization of the IDockableContent interface, please refer to the specific Document implementation, questions can be raised, as far as possible to help solve, write a little simple explanation is not good, but a source of reference, if the source would have helped you, for a recommendation, reply or powder what are good. . .

Source address:

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



If you read this blog, feel something for you, please click on the lower right corner of the [recommended]

If you want to reprint this blog, please indicate the source

If you have any opinions or suggestions for this paper, welcome message

Thank you for reading my blog, please pay attention to the following

Author: Zengg source:

The copyright belongs to the author and blog park there, welcome to reprint, but without the permission of the author must keep this statement, and the connection in the article page is the obvious position, or retain the right to pursue legal responsibilities.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Tiffany at November 13, 2013 - 6:34 AM