Basic AvalonDock usage and AvalonDock usage

Source: Internet
Author: User

Basic AvalonDock usage and AvalonDock usage

AvalonDock is an excellent open-source project used to create a docked layout. It can easily develop a software interface similar to VS2010 in WPF. For complex software systems, the use of a large number of controls makes the interface difficult to manage. AvalonDock helped us solve this problem. To use the AvalonDock function in the WPF project, you must first load the dynamic library provided by AvalonDock: http://avalondock.codeplex.com/releases/view/424371. Currently, the latest library is 2.02. Download the dynamic library and main question Library of AvalonDock, decompress the library, and then: XmlLayoutSerializer serializer = new XmlLayoutSerializer (DockManager); using (var stream = new StreamWriter ("Layout. xml ") {serializer. serialize (stream );}

(2) restore the Layout

XmlLayoutSerializer serializer = new XmlLayoutSerializer(DockManager); using (var stream = new StreamReader("Layout.xml")){     serializer.Deserialize(stream); }

When you restore the layout, you must set the ContentId attribute for the LayoutAnchrobale object and the LayoutDocument object. Otherwise, DockingManager ignores content restoration.

2. Change the topic

AvalonDock provides six theme styles. To use these theme Styles, you must import the Subject Library to the program. DockManger is a DockingManager object. By changing the Theme attribute in DockingManager, you can change the style of the entire interface.

DockManager.Theme = new GenericTheme();//DockManager.Theme = new AeroTheme();//DockManager.Theme = new ExpressionDarkTheme();//DockManager.Theme = new ExpressionLightTheme();//DockManager.Theme = new MetroTheme();//DockManager.Theme = new VS2010Theme();

3. RootSide operation

Dynamically change the content of the LayoutRoot. LeftSide object.

(1) code in xaml

<avalon:LayoutRoot.LeftSide>       <avalon:LayoutAnchorSide>                <avalon:LayoutAnchorGroup x:Name="LeftGroup">                                                  </avalon:LayoutAnchorGroup>       </avalon:LayoutAnchorSide></avalon:LayoutRoot.LeftSide>

(2) Background code

private void miLeft_Click_1(object sender, RoutedEventArgs e) {            try            {                LayoutAnchorable anchorable = new LayoutAnchorable();                anchorable.Title = "Left";                LeftGroup.Children.Add(anchorable);            }            catch (Exception ex)            {                MessageBox.Show(ex.Message, "[MainWindow][miLeft_Click_1]");            } }

4. Pane operation

Dynamically change the pane layout in the software.

(1) code in xaml

<Avron: DockingManager x: Name = "DockManager"> <avron: DockingManager. theme> <aveon: ExpressionDarkTheme/> </aveon: DockingManager. theme> <aveon: LayoutRoot x: Name = "Root"> <aveon: LayoutPanel x: Name = "Panel"> <aveon: LayoutAnchorablePaneGroup x: name = "LeftAnchorableGroup" DockWidth = "300"> <aveon: LayoutAnchorablePane x: Name = "LeftPane"> <aveon: LayoutAnchorable x: name = "Solution" Title = "Solution" ContentId = "Solution"/> </aveon: LayoutAnchorablePane> </aveon: LayoutAnchorablePaneGroup> <aveon: LayoutAnchorablePane> <aveon: layoutAnchorable> </aveon: Schedule> <aveon: LayoutDocumentPane> <aveon: LayoutDocument> </aveon: LayoutDocumentPane> <aveon: layoutDocumentPaneGroup x: Name = "DocumentGroup"> <aveon: LayoutDocumentPane x: Name = "DocumentPane"> <aveon: LayoutDocument Title = "document" ContentId = "document"> </aveon: layoutDocument> </aveon: LayoutDocumentPane> </aveon: LayoutDocumentPaneGroup> <aveon: Snapshot x: Name = "RightAnchorableGroup" Orientation = "Vertical" DockWidth = "300"> <aveon: layoutAnchorablePane x: Name = "RightPane"> <aveon: LayoutAnchorable Title = "attribute" ContentId = "Property"/> </aveon: LayoutAnchorablePane> </aveon: layoutAnchorablePaneGroup> </aveon: LayoutPanel> </aveon: LayoutRoot> </aveon: DockingManager>

(2) Add horizontal AnchorablePane

Private void miAnchorPane_Click_1 (object sender, RoutedEventArgs e) {try {LayoutAnchorablePane pane = new neighbor (); LayoutAnchorable anchorable = new LayoutAnchorable (); anchorable. title = "Horizontal Direction"; pane. children. add (anchorable); LeftAnchorableGroup. children. add (pane);} catch (Exception ex) {MessageBox. show (ex. message, "[MainWindow] [miAnchorPane_Click_1]") ;}}

(3) add vertical AnchorablePane

Private void reply (object sender, RoutedEventArgs e) {try {LayoutAnchorablePane pane = new LayoutAnchorablePane (); LayoutAnchorable anchorable = new LayoutAnchorable (); anchorable. title = "vertical"; pane. children. add (anchorable); RightAnchorableGroup. children. add (pane);} catch (Exception ex) {MessageBox. show (ex. message, "[MainWindow] [miAnchorVerticalPane_Click_1]") ;}}

(4) add DocumentPane

private void miDocumentPane_Click_1(object sender, RoutedEventArgs e) {            try            {                LayoutDocumentPane documentPane = new LayoutDocumentPane();                LayoutDocument document = new LayoutDocument();                document.Title = "document";                document.Content = new RichTextBox();                documentPane.Children.Add(document);                DocumentGroup.Children.Add(documentPane);            }            catch (Exception ex)            {                MessageBox.Show(ex.Message, "[MainWindow][miDocumentPane_Click_1]");            } }

5. Floating form display

Private void miSearchWnd_Click_1 (object sender, RoutedEventArgs e) {LayoutAnchorable anchorable = new LayoutAnchorable (); anchorable. title = "query"; anchorable. floatingWidth = 300; anchorable. floatingHeight = 300; anchorable. floatingTop = 200; anchorable. floatingLeft = 300; Button button = new Button (); button. content = "query"; button. width = 80; button. height = 40; anchorable. content = button; LeftPane. children. add (anchorable); anchorable. float (); // call the Float method to make the form floating display}

6. Hide the form display

Private void miRestoreHideWnd_Click_1 (object sender, RoutedEventArgs e) {try {if (Root. Hidden! = Null) {while (Root. Hidden. Count> 0) {Root. Hidden [0]. Show (); // call the show method to restore the display of the form. }}} Catch (Exception ex) {MessageBox. Show (ex. Message, "[MainWindow] [miRestoreHideWnd_Click_1]");}

7. Form operations

(1) Add Anchorable

Private void miAddAnchroable_Click_1 (object sender, RoutedEventArgs e) {LayoutAnchorable anchorable = new LayoutAnchorable (); anchorable. title = "tool"; Button btn = new Button (); btn. content = "this is a test button"; anchorable. content = btn; btn. height = 30; btn. width = 150; anchorable. isActive = true; RightPane. children. add (anchorable );}

(2) Add Document

private void miAddDocument_Click_1(object sender, RoutedEventArgs e){            LayoutDocument document = new LayoutDocument();            document.Title = "doc";            document.Content = new RichTextBox();            document.IsActive = true;            DocumentPane.Children.Add(document);}

(3) add and display a form

Private void miOutPutWnd_Click_1 (object sender, RoutedEventArgs e) {LayoutAnchorable anchorable = new LayoutAnchorable (); anchorable. title = "output"; anchorable. content = new RichTextBox (); anchorable. addToLayout (DockManager, AnchorableShowStrategy. bottom );}

(4) automatically hide after form Switching

private void miAutoHide_Click_1(object sender, RoutedEventArgs e) {            if (Solution != null)            {                Solution.ToggleAutoHide();            } }

Now, you need to learn about the basic usage of AvalonDock. For how to change the appearance style of AvalonDock and use advanced usage such as MVVM mode, you must learn it by yourself.

Complete source code download: http://download.csdn.net/detail/tianwenxue/8871487

This article is original. For more information, see the source.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.