• WPF 选项卡


    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;
    
                    }
                }
    

      

  • 相关阅读:
    随机生成30道四则运算题目
    《构建之法》阅读笔记01
    第一周学习进度
    个人介绍
    MyBatis(登录)
    MyBatis
    动态网页
    网页基本标签
    Servlet基础
    JSP数据交互
  • 原文地址:https://www.cnblogs.com/lizhenhong/p/9327441.html
Copyright © 2020-2023  润新知