從零開始學習AvalonDock(1)


由於個人需要,時不時得開發上位機程序,之前用過WIN API和C# WIN FORM,但都是開發一兩個程序就不用了。這次又需要弄一個上位機,為了不花大量精力來弄界面,經過兩天業余時間的搜索資料,決定選用WPF。
這個程序需要有類似VS2008和KEIL等軟件的DOCKING PANEL功能,選用了開源的控件AVALONDOCK。
 
本人非專職上位機開發人員,只求用最快的速度達到需求,只把WPF的概念大約了解了一下,不打算單獨研究XAML的語法。先建立一個DEMO感受一下,獲得一些成就感是明智的。
 
新建一個空的工程,在references中添加avalondock的DLL,然后把XMAL文件按如下修改
View Code
<Window x:Class="WpfApplication4.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:avalonDock="clr-namespace:AvalonDock;assembly=AvalonDock"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="24"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="24"/>
        </Grid.RowDefinitions>
        <Menu>
            <MenuItem Header="File">
                <MenuItem Header="Exit"/>
            </MenuItem>
        </Menu>

        <avalonDock:DockingManager Grid.Row="1" x:Name="dockManager" >

            <StatusBar Grid.Row="2">
            <StatusBarItem Content="AvalonDock 1.3 Sample Project"/>
        </StatusBar>
        </avalonDock:DockingManager>
    </Grid>
        
</Window>
然后增加
View Code
<avalonDock:ResizingPanel Orientation="Horizontal">
                <avalonDock:DockablePane>
                    <avalonDock:DockableContent x:Name="classesContent" Title="Classes"/>
                </avalonDock:DockablePane>
                <avalonDock:DocumentPane>
                    <avalonDock:DocumentContent Title="MyDocument!"/>
                </avalonDock:DocumentPane>
            </avalonDock:ResizingPanel>

 

也可以不要上面那部分代碼,后台代碼修改成如下,職業習慣,我更喜歡在后台生成窗口。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using AvalonDock;

namespace WpfApplication4
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            var resPanel = new ResizingPanel() { Orientation = Orientation.Horizontal };
            var dockPane = new DockablePane() { };
            var documentPane = new DocumentPane() { };

            dockPane.Items.Add(new DockableContent()
            {
                Name = "classesContent",
                Title = "Classes"
            });

            documentPane.Items.Add(new DocumentContent()
            {
                Title = "My Document!"
            });

            resPanel.Children.Add(dockPane);
            resPanel.Children.Add(documentPane);
            dockManager.Content = resPanel;
        }
    }
}

運行一下就會出來一個具有浮動和自動停靠等功能的DEMO程序。

 

以上程序來源:http://avalondock.codeplex.com/wikipage?title=GettingStarted&referringTitle=Documentation


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM