How to: Add and Customize the Ribbon Skin List and Skin Gallery

2024-06-09 1204阅读

皮肤列表和皮肤库允许用户选择皮肤。本文介绍如何在功能区中显示“皮肤列表”或“皮肤库”并对其进行自定义。

DevExpress演示中心中的大多数应用程序都允许您选择皮肤。例如,运行XtraGrid演示并导航到皮肤功能区页面以更改当前皮肤。

How to: Add and Customize the Ribbon Skin List and Skin Gallery

在功能区UI中显示皮肤列表或皮肤库

使用以下栏项将相应的UI元素添加到功能区UI:“Skin List, Skin Gallery”、“Skin Palette List”和“Skin Palette Gallery”。在RibbonPageGroup上单击鼠标右键,然后调用相应的命令在设计时添加“ Skin List ”或“Skin Gallery”。

How to: Add and Customize the Ribbon Skin List and Skin Gallery

Skin List

A Skin List (SkinDropDownButtonItem) is a drop-down menu that displays application skins.

How to: Add and Customize the Ribbon Skin List and Skin Gallery

Skin Gallery

A Skin Gallery (SkinRibbonGalleryBarItem) is an in-ribbon gallery that displays skins. Skins in the gallery are grouped into categories.

How to: Add and Customize the Ribbon Skin List and Skin Gallery

Skin Palette List

A Skin Palette List (SkinPaletteDropDownButtonItem) allows users to select a color palette for a vector skin.

How to: Add and Customize the Ribbon Skin List and Skin Gallery

Skin Palette Gallery

A Skin Palette Gallery (SkinPaletteRibbonGalleryBarItem) allows users to select a color palette in an embedded or dropdown gallery.

How to: Add and Customize the Ribbon Skin List and Skin Gallery

Example

How to: Add and Customize the Ribbon Skin List and Skin Gallery

using DevExpress.XtraBars;
using DevExpress.XtraBars.Ribbon;
namespace DXApplication20 {
    public partial class Form1 : RibbonForm {
        public Form1() {
            InitializeComponent();
            skinPageGroup.ItemLinks.Add(new SkinDropDownButtonItem());
            skinPageGroup.ItemLinks.Add(new SkinRibbonGalleryBarItem());
            colorPalettePageGroup.ItemLinks.Add(new SkinPaletteDropDownButtonItem());
            colorPalettePageGroup.ItemLinks.Add(new SkinPaletteRibbonGalleryBarItem());
        }
    }
}

Display Advanced Skin Options

显示高级skin选项

以下示例演示如何显示与高级皮肤设置相对应的预先设计的功能区UI命令:

How to: Add and Customize the Ribbon Skin List and Skin Gallery

using DevExpress.XtraBars;
using DevExpress.XtraBars.Helpers;
namespace DXRibbonSkinSekector {
    public partial class Form1 : DevExpress.XtraBars.Ribbon.RibbonForm {
        BarCheckItem bciTrackWindowsAppMode, bciOriginalPalette, bciTrackWindowsAccentColor;
        BarButtonItem bbiSystemAccentColor, bbiAccentCustomColor2;
        public Form1() {
            InitializeComponent();
            bciTrackWindowsAppMode = new BarCheckItem();
            bciOriginalPalette = new BarCheckItem();
            bciTrackWindowsAccentColor = new BarCheckItem();
            bbiSystemAccentColor = new BarButtonItem();
            bbiAccentCustomColor2 = new BarButtonItem();
            advancedOptionsGroup.ItemLinks.Add(bciTrackWindowsAppMode);
            advancedOptionsGroup.ItemLinks.Add(bciOriginalPalette);
            advancedOptionsGroup.ItemLinks.Add(bciTrackWindowsAccentColor);
            advancedOptionsGroup.ItemLinks.Add(bbiSystemAccentColor);
            /*
             * "The Bezier" skin supports the second accent color.
             * Other skins do not support the second accent color.
             */
            advancedOptionsGroup.ItemLinks.Add(bbiAccentCustomColor2);
            // Initializes corresponding skin settings/selectors.
            SkinHelper.InitTrackWindowsAppMode(bciTrackWindowsAppMode);
            SkinHelper.InitResetToOriginalPalette(bciOriginalPalette);
            SkinHelper.InitTrackWindowsAccentColor(bciTrackWindowsAccentColor);
            SkinHelper.InitCustomAccentColor(Ribbon.Manager, bbiSystemAccentColor);
            SkinHelper.InitCustomAccentColor2(Ribbon.Manager, bbiAccentCustomColor2);
        }
    }
}

Hide Specific Items And Groups

隐藏特定项目和组

下面的步骤描述了如何隐藏单个皮肤。

  • Create a string array that contains unwanted skin names. These names can be full (e.g., “Office 2016 Colorful”) or partial (e.g., “2007”).
    string[] skinsToHide = { "Seven Classic", "DevExpress Style", "Dark", "2010", "2007", "Sharp" };
    
    • Define a custom method that will iterate through skin items and hide unwanted ones.
      private void HideGalleryItemsByCaptions(RibbonGalleryBarItem galleryItem, string[] skinsToHide) {
          var allItems = galleryItem.Gallery.GetAllItems();
          foreach (GalleryItem item in allItems) {
              if (skinsToHide.Contains(item.Caption))
                  item.Visible = false;
          }
      }
      
      • Use the form or UserControl Load event handler to call your method.
        this.Load += ucRibbon_Load;
        void ucRibbon_Load(object sender, EventArgs e) {
            HideGalleryItemsByCaptions(skinRibbonGalleryBarItem1, skinsToHide);
        }
        

        To hide an entire skin group, use the code sample below.

        要隐藏整个皮肤组,请使用下面的代码示例。

        void ucRibbon_Load(object sender, EventArgs e) {
            skinRibbonGalleryBarItem1.Gallery.Groups.Remove(skinRibbonGalleryBarItem1.Gallery.Groups.OfType()
                    .First(x => String.Equals(x.Caption, "Bonus Skins")));
        }
        

        The following example demonstrates how to rename and hide gallery groups in SkinDropDownButtonItem:

        以下示例演示如何在SkinDropDownButtonItem中重命名和隐藏图库组:

        using System.Linq;
        using DevExpress.XtraBars;
        using DevExpress.XtraBars.Ribbon;
        using DevExpress.XtraBars.Ribbon.Gallery;
        using DevExpress.XtraBars.Helpers;
        namespace DXApplication20 {
            public partial class Form1 : RibbonForm {
                SkinDropDownButtonItem skinDropDownButtonItem;
                public Form1() {
                    InitializeComponent();
                    skinDropDownButtonItem = new SkinDropDownButtonItem(ribbonControl1.Manager);
                    skinPageGroup.ItemLinks.Add(skinDropDownButtonItem);
                }
                private void Form1_Load(object sender, System.EventArgs e) {
                    HideItems(skinDropDownButtonItem);
                }
                void HideItems(SkinDropDownButtonItem skinItem) {
                    GalleryControlGallery gallery = ((skinItem.DropDownControl as SkinPopupControlContainer).Controls.OfType().FirstOrDefault()).Gallery;
                    gallery.Groups[0].Caption = "My Custom Caption";
                    gallery.Groups[1].Visible = false;
                    gallery.Groups[2].Visible = false;
                }
            }
        }
        

        The following example demonstrates how to hide the specified groups from SkinPaletteDropDownButtonItem:

        以下示例演示如何从SkinPartiteDropDownButtonItem中隐藏指定的组:

        void HideSkins2(SkinPaletteDropDownButtonItem skinItem, string[] palettesToHide) {
            var groups = (skinItem.DropDownControl as GalleryDropDown).Gallery.Groups;
            for(var i = 0; i  
        

        Remove Item Grouping

        To remove item grouping, add a new gallery group and populate it with all existing gallery items. Then, you can remove all gallery groups except for your new custom group – as illustrated in the code sample below.

        若要删除项目分组,请添加一个新的库组,并用所有现有库项目填充该组。然后,您可以删除除新的自定义组之外的所有库组,如下面的代码示例所示。

        void ucRibbon_Load(object sender, EventArgs e) {
            RemoveGrouping();
        }
        void RemoveGrouping() {
            GalleryItemGroup group = new GalleryItemGroup() { Caption = "Available Skins" };
            skinRibbonGalleryBarItem1.Gallery.Groups.Insert(0, group);
            foreach(var item in skinRibbonGalleryBarItem1.Gallery.GetAllItems()) {
                skinRibbonGalleryBarItem1.Gallery.Groups[0].Items.Add(item);
            }
            while(skinRibbonGalleryBarItem1.Gallery.Groups.Count > 1)
                skinRibbonGalleryBarItem1.Gallery.Groups.Remove(skinRibbonGalleryBarItem1.Gallery.Groups.Last());
        }
        

        Change Captions and Icons Manually

        手动更改标题和图标

        To change captions and glyphs of items within a Ribbon skin gallery, iterate through gallery items and modify the following properties:

        要更改功能区皮肤库中项目的标题和图示符,请遍历库项目并修改以下属性:

        • GalleryItem.Caption — Gets or sets the item’s caption. 获取或设置项的标题
        • GalleryItem.Hint — Gets a hint associated with the gallery item. 获取与库项目关联的提示。
        • GalleryItem.Description — Gets or sets the item’s description.获取或设置项的描述。
        • GalleryItem.ImageOptions.SvgImage — Gets or sets a vector image. The vector image has priority over the raster image.获取或设置矢量图像。矢量图像的优先级高于光栅图像。
        • GalleryItem.ImageOptions.Image — Gets or sets a raster image. To display a custom raster image, nullify the default vector image. 获取或设置光栅图像。若要显示自定义光栅图像,请使默认矢量图像无效。
        • GalleryItem.ImageOptions.HoverImage — Gets or sets a raster image displayed when the mouse pointer hovers the item. 获取或设置鼠标指针悬停项目时显示的光栅图像。
          void ucRibbon_Load(object sender, EventArgs e) {
              CustomizeItems(skinRibbonGalleryBarItem1);
          }
          void CustomizeItems(SkinRibbonGalleryBarItem target) {
              foreach(var item in target.Gallery.GetAllItems()) {
                  if(item.Caption == "DevExpress Dark Style") {
                      item.Caption = item.Hint = "Default Skin";
                      item.Description = "The default skin";
                      // We recommend that you use vector images.
                      item.ImageOptions.SvgImage = SvgImage.FromResources("DXApplication1.Resources.Driving.svg", typeof(Form1).Assembly);
                      // The vector image has priority over the raster image.
                      // To assign a raster image, nullify the default vector image.
                      item.ImageOptions.SvgImage = null;
                      item.ImageOptions.Image = DevExpress.Images.ImageResourceCache.Default.GetImage("office2013/miscellaneous/colors_16x16.png");
                      item.ImageOptions.HoverImage = DevExpress.Images.ImageResourceCache.Default.GetImage("office2013/miscellaneous/colors_32x32.png");
                  }
              }
          }
          

          How to: Add and Customize the Ribbon Skin List and Skin Gallery

          Obtain Active Skin

          The following example demonstrates how to get the active skin name:

          string activeSkinName = DevExpress.UserLookAndFeel.Default.ActiveSkinName;
          
VPS购买请点击我

免责声明:我们致力于保护作者版权,注重分享,被刊用文章因无法核实真实出处,未能及时与作者取得联系,或有版权异议的,请联系管理员,我们会立即处理! 部分文章是来自自研大数据AI进行生成,内容摘自(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供学习参考,不准确地方联系删除处理! 图片声明:本站部分配图来自人工智能系统AI生成,觅知网授权图片,PxHere摄影无版权图库和百度,360,搜狗等多加搜索引擎自动关键词搜索配图,如有侵权的图片,请第一时间联系我们,邮箱:ciyunidc@ciyunshuju.com。本站只作为美观性配图使用,无任何非法侵犯第三方意图,一切解释权归图片著作权方,本站不承担任何责任。如有恶意碰瓷者,必当奉陪到底严惩不贷!

目录[+]