1、引用
xmlns:xcad="http://schemas.xceed.com/wpf/xaml/avalondock"
2、xaml代码
<xcad:DockingManager x:Name="dockManager" Grid.Row="1" Grid.Column="0" Background="#f1f1f1"> <xcad:DockingManager.Theme> <xcad:AeroTheme/> </xcad:DockingManager.Theme> <xcad:LayoutRoot> <xcad:LayoutPanel > <xcad:LayoutAnchorablePaneGroup DockWidth="220" > <xcad:LayoutAnchorablePane> <xcad:LayoutAnchorable Title="导航栏" ContentId="text1" CanHide="False" CanClose="False" CanFloat="False"> <Border Grid.Row="1" Grid.Column="0" IsHitTestVisible="True" x:Name="barmune" BorderBrush="Transparent" /> </xcad:LayoutAnchorable> </xcad:LayoutAnchorablePane> </xcad:LayoutAnchorablePaneGroup> <xcad:LayoutDocumentPane > <xcad:LayoutDocument ContentId="FirstPage" Title="首页 " CanClose="False" CanFloat="False"> //在此增加元素 </xcad:LayoutDocument> </xcad:LayoutDocumentPane> </xcad:LayoutPanel> </xcad:LayoutRoot> </xcad:DockingManager>
3、增加选项卡
引用 Xceed.Wpf.AvalonDock.dll
private void AddTab(string tabName) { var firstDocumentPane = dockManager.Layout.Descendents().OfType<LayoutDocumentPane>().FirstOrDefault(); if (firstDocumentPane != null) { LayoutDocument ldoc = firstDocumentPane.Children.OfType<LayoutDocument>().Where(o => o.Title == tabName).FirstOrDefault(); if (ldoc != null) { ldoc.IsSelected = true; } else { LayoutDocument doc = new LayoutDocument(); doc.CanFloat = false; var uc = new MyUserControl();//实例化UserControl doc.Content = uc; doc.Title = tabName; firstDocumentPane.Children.Add(doc); doc.IsActive = true; } }