How to preview UI changes using WinUI Ribbon Gallery?
The WinUI
Ribbon Gallery feature includes a live preview of selected items
before applying it.
When preview support is
enabled, the Ribbon Gallery allows users to preview a command before making a
selection, providing a real-time view of how the change will affect the
application. This is especially useful for previewing different font styles,
color schemes, and other design elements.
To enable this feature, users can utilize the ‘ItemPointerEnter’ and
‘ItemPointerExit’ events.
Example:
This example demonstrates a simple design application where a color scheme is applied to an icon. The Ribbon Gallery includes three built-in color palette items: Green, Pink, and Violet. Hovering over a palette item previews how the icon will appear with that color scheme before it's applied.
Step 1: Attach the ‘ItemPointerEnter’ and ‘ItemPointerExit’ events to enable preview feature.
XAML
<ribbon:RibbonGallery x:Name="colorGallery"
ItemHeight="70"
SizeMode="Large"
ItemWidth="100"
MaxColumnCount="5"
SelectedItem="{x:Bind SelectedItem}"
ItemPointerEnter="OnItemPointerEnter"
ItemPointerExit="OnItemPointerExit">
<ribbon:RibbonGallery.Items>
…….
</ribbon:RibbonGallery.Items>
</ribbon:RibbonGallery>
Step 2: Added a code to update the colors based on palette color on home icon.
C#
private void OnItemPointerEnter(object sender, RibbonRoutedEventArgs e)
{
RibbonGalleryItem previewedItem = (e.Source) as RibbonGalleryItem;
UpdateColorScheme(previewedItem);
}
private void OnItemPointerExit(object sender, RibbonRoutedEventArgs e)
{
RibbonGalleryItem selecteditem = (e.Source) as RibbonGalleryItem;
UpdateColorScheme (selecteditem);
}
private void UpdateColorScheme (RibbonGalleryItem galleryItem)
{
if (galleryItem != null)
{
Grid content = (Grid)((Viewbox)galleryItem.Content).Child;
Color doorColor = ((SolidColorBrush)((Path)content.Children[0]).Fill).Color;
Color windowColor = ((SolidColorBrush)((Path)content.Children[1]).Fill).Color;
Color wallColor = ((SolidColorBrush)((Path)content.Children[2]).Fill).Color;
home.Fill = new SolidColorBrush(wallColor);
window.Fill = new SolidColorBrush(windowColor);
door.Fill = new SolidColorBrush(doorColor);
}
}
Output:

Conclusion:
I hope you enjoyed learning how to preview UI changes using Ribbon Gallery.
You can refer to our WinUI Ribbon’s feature tour page to learn about its other groundbreaking feature representations. You can also explore our WinUI Ribbon documentation to understand how to present and manipulate data.
For current customers, you can check out our WinUI components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our WinUI Ribbon and other WinUI components.
If you have any queries or require clarifications, please let us know in the comment section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!