Description:
How to hide unnecessary skins and skin groups from the skin gallery?
Answer:
1. REMOVE (HIDE) A SPECIFIC SKIN
Traverse through the gallery group collection, then through its gallery item collection and hide a corresponding item:
C#private void InitRibbonSkinGallery() {
SkinHelper.InitSkinGallery(skinGalleryBarItem);
}
string[] skinsToHide = {"Black","Blue","Seven","Sharp" }; // populate with names of unnecessary skins
private void HideSkins(string[] skinsToHide) {
for(var i = 0; i < skinGalleryBarItem.Gallery.Groups.Count; i++) {
var group = skinGalleryBarItem.Gallery.Groups[i];
if(group == null) {
continue;
}
for(var j = 0; j < group.Items.Count; j++) {
var item = group.Items[j];
if(item == null) {
continue;
}
foreach(var skin in skinsToHide) {
if(String.Equals(item.Caption, skin)) {
item.Visible = false;
}
}
}
}
}
Visual Basic 6Private Sub InitRibbonSkinGallery()
SkinHelper.InitSkinGallery(skinGalleryBarItem)
End Sub
Private skinsToHide() As String = {"Black","Blue","Seven","Sharp" } 'populate with names of unnecessary skins
Private Sub HideSkins(ByVal skinsToHide() As String)
For i = 0 To skinGalleryBarItem.Gallery.Groups.Count - 1
Dim group = skinGalleryBarItem.Gallery.Groups(i)
If group Is Nothing Then
Continue For
End If
For j = 0 To group.Items.Count - 1
Dim item = group.Items(j)
If item Is Nothing Then
Continue For
End If
For Each skin In skinsToHide
If String.Equals(item.Caption, skin) Then
item.Visible = False
End If
Next skin
Next j
Next i
End Sub
This is discussed in the How to remove certain skins from the bonus skins collection ticket.
2. REMOVE A SPECIFIC SKIN GROUP
Remove a required group from the collection:
C#string skinGroup = "Standard Skins";
RemoveSkinGroups(skinGroup);
void RemoveSkinGroups(string skinGroup) {
skinGalleryBarItem.Gallery.Groups.Remove(skinGalleryBarItem.Gallery.Groups.OfType<GalleryItemGroup>().First(x => String.Equals(x.Caption, skinGroup)));
}
Visual Basic 6Dim skinGroup As String = "Standard Skins"
RemoveSkinGroups(skinGroup, SkinRibbonGalleryBarItem1)
'...
Private Sub RemoveSkinGroups(skinGroup As String, item As SkinRibbonGalleryBarItem)
item.Gallery.Groups.Remove(item.Gallery.Groups.OfType(Of GalleryItemGroup)().First(Function(x) [String].Equals(x.Caption, skinGroup)))
End Sub
This issue is discussed in the How to remove the "Theme Skin" skin group from the In-Ribbon gallery populated with available skins thread.
3. REMOVE GROUPING
Fill the In-Ribbon and In-Dropdown gallery with required skins manually.
To obtain all available skins in your project, use the SkinManager.Skinsproperty. To populate the In-Dropdown gallery, handle theRibbonGalleryBarItem.GalleryInitDropDownGalleryevent:
C#DevExpress.XtraBars.RibbonGalleryBarItem skinGalleryBarItem;
SkinContainerCollection skins;
void InitSkinGallery() {
//SkinHelper.InitSkinGallery(skinGalleryBarItem, true);
skins = SkinManager.Default.Skins;
for (int i = 0; i < 14; i++) {
int index = rgbiSkins.Gallery.Groups[0].Items.Add(new GalleryItem());
GalleryItem item = skinGalleryBarItem.Gallery.Groups[0].Items[index];
item.Description = skins[index].SkinName;
item.Image = galleryImageCollection.Images[i];
}
}
private void skinGalleryBarItem_GalleryInitDropDownGallery(object sender, InplaceGalleryEventArgs e) {
e.PopupGallery.AllowHoverImages = false;
e.PopupGallery.ItemClick += new GalleryItemClickEventHandler(PopupGallery_ItemClick);
for (int i = 0; i < e.PopupGallery.Groups[0].Items.Count; i++) {
GalleryItem item = e.PopupGallery.Groups[0].Items[i];
item.Description = skins[i].SkinName;
item.Caption = skins[i].SkinName;
}
}
void PopupGallery_ItemClick(object sender, GalleryItemClickEventArgs e) {
defaultBarAndDockingController1.Controller.LookAndFeel.SkinName = e.Item.Description;
}
Visual Basic 6Private skinGalleryBarItem As DevExpress.XtraBars.RibbonGalleryBarItem
Private skins As SkinContainerCollection
Private Sub InitSkinGallery()
'SkinHelper.InitSkinGallery(skinGalleryBarItem, true);
skins = SkinManager.Default.Skins
For i As Integer = 0 To 13
Dim index As Integer = rgbiSkins.Gallery.Groups(0).Items.Add(New GalleryItem())
Dim item As GalleryItem = skinGalleryBarItem.Gallery.Groups(0).Items(index)
item.Description = skins(index).SkinName
item.Image = galleryImageCollection.Images(i)
Next i
End Sub
Private Sub skinGalleryBarItem_GalleryInitDropDownGallery(ByVal sender As Object, ByVal e As InplaceGalleryEventArgs)
e.PopupGallery.AllowHoverImages = False
AddHandler e.PopupGallery.ItemClick, AddressOf PopupGallery_ItemClick
For i As Integer = 0 To e.PopupGallery.Groups(0).Items.Count - 1
Dim item As GalleryItem = e.PopupGallery.Groups(0).Items(i)
item.Description = skins(i).SkinName
item.Caption = skins(i).SkinName
Next i
End Sub
Private Sub PopupGallery_ItemClick(ByVal sender As Object, ByVal e As GalleryItemClickEventArgs)
defaultBarAndDockingController1.Controller.LookAndFeel.SkinName = e.Item.Description
End Sub
See Skin Gallery - How to remove skin grouping ticket to learn more.
4. CHANGE A SKIN NAME
Traverse through the gallery group collection, then through its gallery item collection, obtain a required GalleryItem and change the GalleryItem.Caption property for this purpose.
See How to change/remove the DevExpress Style caption from the Skin Menu/Drop-down gallery for more information.
5. CHANGE A SKIN ICON
Traverse through the gallery group collection, then through its gallery item collection, obtain a required GalleryItem and set the Image and HoverImage properties.
See Skin Gallery - How to change a skin icon (image) and name (caption) for more information.
Hi, I need help, how can I set a skin to the ribbon control from the Skin helper galery by code??
Thanks
Hello,
To process your recent post more efficiently, I created a separate ticket on your behalf: T198114: How to set a skin to the ribbon control from the Skin helper galery by code. This ticket is currently in our processing queue. Our team will address it as soon as we have any updates.
Can you post an update to this using the new 18.1 SkinDropDownButtonItem?
Hi Larry,
In general, you can use the same code with SkinDropDownButtonItem. The only difference is how to get a proper GalleryControl to update its items. In the case of SkinDropDownButtonItem, use the following code for this:
GalleryControlGallery gallery = ((skinDropDownButtonItem.DropDownControl as SkinPopupControlContainer).Controls.OfType<GalleryControl>().FirstOrDefault()).Gallery;
Dim gallery As GalleryControlGallery = ((TryCast(skinDropDownButtonItem1.DropDownControl, SkinPopupControlContainer)).Controls.OfType(Of GalleryControl)().FirstOrDefault()).Gallery
Please try this code and let me know if you have any further questions.
How do I set some groups as "not selected" before first time the "skinDropDownButtonItem1" is shown?
(see attachment)
Hello Martin,
I have created a separate ticket on your behalf (T664633: How to hide certain groups displayed in SkinDropDownButtonItem). I will address it shortly.
Great