How to set context menu for TileViewItems in TileView Control
This article describes how to set context menu for all the items in TileViewControl.
ContextMenu
Create and add menu items to the ContextMenu. Using ItemContainerStyle property of TileViewControl, set the context menu for all TileViewItems.
The following code example demonstrates the same.
XAML
<Window x:Class="TileViewControl_ContextMenu.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" xmlns:syncfusion="http://schemas.syncfusion.com/wpf" Title="TileViewControl ContextMenu" Height="350" Width="525"> <Grid> <syncfusion:TileViewControl> <syncfusion:TileViewControl.ItemContainerStyle> <Style TargetType="syncfusion:TileViewItem"> <Setter Property="ContextMenu"> <Setter.Value> <ContextMenu> <MenuItem Header="MenuItem"> <MenuItem.Style> <Style TargetType="MenuItem"> <EventSetter Event="MenuItem.Click" Handler="MenuItem_Click"/> </Style> </MenuItem.Style> </MenuItem> </ContextMenu> </Setter.Value> </Setter> </Style> </syncfusion:TileViewControl.ItemContainerStyle> <syncfusion:TileViewItem Header="TileViewItem 1" Content="TileViewContent" /> <syncfusion:TileViewItem Header="TileViewItem 2" Content="TileViewContent"/> <syncfusion:TileViewItem Header="TileViewItem 3" Content="TileViewContent" /> <syncfusion:TileViewItem Header="TileViewItem 4" Content="TileViewContent" /> <syncfusion:TileViewItem Header="TileViewItem 5" Content="TileViewContent" /> <syncfusion:TileViewItem Header="TileViewItem 6" Content="TileViewContent" /> </syncfusion:TileViewControl> </Grid> </Window>
C#
private void MenuItem_Click(object sender, RoutedEventArgs e) { MessageBox.Show("MenuItem clicked"); }
The following screenshots illustrates the output of the above code example
I hope you enjoyed learning about how to set the context menu for TileViewItems in WPF TileView Control.
You can refer to our WPF Tile View feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our WPF Tile View example to understand how to create and manipulate data.
For current customers, you can check out our 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 other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!