美文网首页
动态添加RibbonPageGroup/NavBarGroup

动态添加RibbonPageGroup/NavBarGroup

作者: 秒怂的哈士奇爱吃西瓜 | 来源:发表于2021-06-23 15:21 被阅读0次

    ---------------------------RibbonPageGroup----------------------------

    //设置数组
     private List<BarButtonItem> barButtonItemList;
     private RibbonPage pageDataAnalysis;
     private void BuildUIElements()
        {
         barButtonItemList = new List<BarButtonItem>();
      //动态生成菜单---------------------------------
            DataAnalysisServiceClient client = new DataAnalysisServiceClient();
            IList<MenuManage> MenuMannages = client.GetAllMenuManage();
    //循环数组
            foreach (var item in MenuMannages)
            {
                if (string.IsNullOrWhiteSpace(item.ParentId))
                {
                    //添加组
                    RibbonPageGroup ribbonPageGroup = new DevExpress.XtraBars.Ribbon.RibbonPageGroup(item.MenuName);//菜单卡分组定义
                    ribbonPageGroup.Text = item.MenuName.ToString();//卡片组名
                    pageDataAnalysis.Groups.Add(ribbonPageGroup);
                    //功能按钮
                    BarButtonItem barButtonItem = new DevExpress.XtraBars.BarButtonItem();
                    barButtonItem.Caption = item.MenuName.ToString();
                    barButtonItem.Hint = item.MenuName.ToString();
                   //加载Icon
                    Image image = Path.Combine(绝对地址);
                    barButtonItem.LargeGlyph = image;
                    barButtonItem.Description = item.Code;
                    ribbonPageGroup.ItemLinks.Add(barButtonItem);
                    barButtonItem.ItemClick += new DevExpress.XtraBars.ItemClickEventHandler(this.barMenuItem_ItemClick);//注册事件
                }
                
            }
            InitSkinGallery();
        }
    -------------------------------
    //事件触发
    void barMenuItem_ItemClick(object sender, ItemClickEventArgs s)
        {
            this.SmartParts.Add(FrmMenuData.Instance(s.Item.Description));
            contentWorkspace.Show(FrmMenuData.Instance(s.Item.Description));
        
        }
    

    ---------------------------NavBarGroup/NavBarItem----------------------------

    //设置新的NavBarGroup-------------------
     NavBarGroup nbGroup1 = new NavBarGroup();
     nbGroup1.Name = "nbGroup1";
     nbGroup1.Caption = item.MenuName;
     nbGroup1.SmallImageIndex = -1;
     nbGroup1.LargeImageIndex = -1;
      //添加到导航栏所有分组集合
     navBarControl1.Groups.Add(nbGroup1);
     //设置新的NavBarItem·--------------------------------
     nbItem1.Name = itemSC.Id.ToString()+"."+itemSC.ViewType;
     nbItem1.Caption = itemSC.MenuName;
      nbItem1.SmallImageIndex = -1;
      nbItem1.LargeImageIndex = -1;
      //添加到导航栏所有子项目集合
      navBarControl1.Items.Add(nbItem1);
       nbItem1.LinkClicked += Item_Click;//设置事件
      //添加子项目至某一分组----可触发change
       nbGroup1.ItemLinks.AddRange(new NavBarItemLink[] {
                new NavBarItemLink(nbItem1)
            });
    
    //NavBarItem事件
    
      private void Item_Click(object sender, NavBarLinkEventArgs e)
        { }

    相关文章

      网友评论

          本文标题:动态添加RibbonPageGroup/NavBarGroup

          本文链接:https://www.haomeiwen.com/subject/jwybyltx.html