发布时间:2025-12-09 12:00:30 浏览次数:1
本文简单介绍AvalonDock2.0基本用法,下载AvalonDock 2.0dll及主题http://avalondock.codeplex.com/
AvalonDock基本类介绍
DockingManager:停靠管理类,xaml中AvalonDock的根节点
LayoutRoot:布局根节点,有四个属性LeftSide,RightSide,TopSide,ButtomSide展示四个位置的内容
LayoutPanel:布局面板类,可有多个LayoutGroup,实际的窗格都位于LayoutPanel节点下
LayoutAnchorablePaneGroup:可停靠窗格组类
LayoutDocumentPaneGroup:文档窗格组类
LayoutAnchorablePane:可停靠窗格类
LayoutDocumentPane:文档窗格类
LayoutAnchorable:可停靠内容类
LayoutDocument:文档内容类
xaml布局代码
<Window x:Class="AvalonDockTest.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:avalondock="http://schemas.xceed.com/wpf/xaml/avalondock" Title="MainWindow" Height="350" Width="525"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="auto"/> <RowDefinition></RowDefinition> </Grid.RowDefinitions> <Menu Margin="0" HorizontalAlignment="Left" Name="menu1" VerticalAlignment="Top"> <MenuItem Header="恢复布局" Click="MenuItem_Click"/> <MenuItem Header="断点窗口" Click="MenuItem_Click_1"/> </Menu> <avalondock:DockingManager x:Name="dockingmanger" Grid.Row="1"> <avalondock:DockingManager.Theme> <avalondock:VS2010Theme/> </avalondock:DockingManager.Theme> <avalondock:LayoutRoot> <avalondock:LayoutRoot.LeftSide> <avalondock:LayoutAnchorSide> <avalondock:LayoutAnchorGroup> <avalondock:LayoutAnchorable Title="资源管理器" AutoHideHeight="50" ContentId="l1"> <TextBox Width="80" SelectionChanged="TextBox_SelectionChanged"/> </avalondock:LayoutAnchorable> <avalondock:LayoutAnchorable Title="数据库" AutoHideHeight="50" ContentId="l2"> <TextBox Width="80" SelectionChanged="TextBox_SelectionChanged"/> </avalondock:LayoutAnchorable> </avalondock:LayoutAnchorGroup> </avalondock:LayoutAnchorSide> </avalondock:LayoutRoot.LeftSide> <avalondock:LayoutRoot.BottomSide> <avalondock:LayoutAnchorSide> <avalondock:LayoutAnchorGroup x:Name="buttomgroup"> <avalondock:LayoutAnchorable Title="输出" ContentId="t1"> <TextBox TextWrapping="Wrap" AcceptsReturn="True"></TextBox> </avalondock:LayoutAnchorable> <avalondock:LayoutAnchorable Title="错误" ContentId="t2"> <TextBox TextWrapping="Wrap" AcceptsReturn="True"></TextBox> </avalondock:LayoutAnchorable> </avalondock:LayoutAnchorGroup> </avalondock:LayoutAnchorSide> </avalondock:LayoutRoot.BottomSide> <avalondock:LayoutPanel> <avalondock:LayoutDocumentPane> <avalondock:LayoutDocument Title="MainWindow.xaml" ContentId="d1"> <TextBox AcceptsReturn="True" TextWrapping="Wrap"></TextBox> </avalondock:LayoutDocument> <avalondock:LayoutDocument Title="MainWindow.xaml.cs" ContentId="d2"> <TextBox AcceptsReturn="True" TextWrapping="Wrap"></TextBox> </avalondock:LayoutDocument> </avalondock:LayoutDocumentPane> </avalondock:LayoutPanel> </avalondock:LayoutRoot> </avalondock:DockingManager> </Grid></Window>动态改变
private void MenuItem_Click_1(object sender, RoutedEventArgs e) { try { LayoutAnchorable la = new LayoutAnchorable(); la.Title = "断点"; la.Content = new TextBox(); buttomgroup.Children.Add(la); } catch(Exception ex) { MessageBox.Show(ex.ToString()); } }保存布局
var serializer = new XmlLayoutSerializer(dockingmanger); using(var stream = new StreamWriter("layout.xml")) { serializer.Serialize(stream); }恢复布局
private void MenuItem_Click(object sender, RoutedEventArgs e) { var serializer = new XmlLayoutSerializer(dockingmanger); using(var stream = new StreamReader("layout.xml")) { serializer.Deserialize(stream); } }162118.html