How to add custom context menu in TileViewItem
We can add custom context menu to the item of TileViewControl. The following code example explains the same,
Adding Custom ContextMenu to the TileViewItem :
<syncfusion:TileViewItem.ContextMenu> <ContextMenu> <MenuItem /> <MenuItem /> </ContextMenu> </syncfusion:TileViewItem.ContextMenu>
For instance, we have added new TileViewItem to the TileViewControl and removed existing item to the TileViewControl through the Custom context menu. The following code example demonstrate the same,
Mainwindow.xaml :
<syncfusion:TileViewControl Name="tileViewControl1" >
<syncfusion:TileViewItem x:Name="item1" Header="Item 1" >
<syncfusion:TileViewItem.ContextMenu>
<ContextMenu>
<MenuItem Header="Add" Command="{Binding AddCommand}"/>
<MenuItem Header="Remove" Command="{Binding RemoveCommand}"/>
</ContextMenu>
</syncfusion:TileViewItem.ContextMenu>
</syncfusion:TileViewItem>
<syncfusion:TileViewItem Header="Item 2"/>
<syncfusion:TileViewItem Header="Item 3"/>
<syncfusion:TileViewItem Header="Item 4" />
</syncfusion:TileViewControl>
Mainwindow.cs :
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
this.DataContext = this;
}
private ICommand addCommand;
public ICommand AddCommand
{
get
{
if (addCommand == null)
addCommand = new DelegateCommand<object>(param => AddItem(param), CanAdd);
return addCommand;
}
set { addCommand = value; }
}
private ICommand removeCommand;
public ICommand RemoveCommand
{
get
{
if (removeCommand == null)
removeCommand = new DelegateCommand<object>(param => RemoveItem(param), CanRemove);
return removeCommand;
}
set { removeCommand = value; }
}
private void RemoveItem(object window)
{
int count = this.tileViewControl1.Items.Count - 1;
TileViewItem item = tileViewControl1.Items[count] as TileViewItem;
this.tileViewControl1.Items.Remove(item);
}
private bool CanRemove(object obj)
{
return true ;
}
private bool CanAdd(object param)
{
return true;
}
private void AddItem(object param)
{
int count = this.tileViewControl1.Items.Count + 1;
this.tileViewControl1.Items.Add(new TileViewItem(){Header = " Item "+count+""});
}
}
Screenshot :

Sample :