@using Syncfusion.Blazor.Navigations;
<div id="target" @onclick="click">Right click/Touch hold to open the ContextMenu </div>
<SfContextMenu @ref="ContextMenuObj" Target="#target" Items="@MenuItems">
<ContextMenuEvents OnOpen="OnOpen" Opened="Opened"></ContextMenuEvents>
</SfContextMenu>
@code {
SfContextMenu ContextMenuObj;
public bool isLeftClick = false;
private void click(MouseEventArgs args)
{
this.isLeftClick = true;
ContextMenuObj.Open(args.ClientY, args.ClientX);
}
public List<MenuItem> MenuItems = new List<MenuItem>
{
new MenuItem{ Text = "Cut" },
new MenuItem{ Text = "Copy" },
new MenuItem{ Text = "Paste" }
};
public void OnOpen(BeforeOpenCloseMenuEventArgs args)
{
if (!this.isLeftClick)
{
args.Cancel = true;
}
}
public void Opened(OpenCloseMenuEventArgs args)
{
this.isLeftClick = false;
}
}
<style>
#target {
border: 1px dashed;
height: 150px;
padding: 10px;
position: relative;
text-align: justify;
color: gray;
user-select: none;
}
</style> |
@using Syncfusion.Blazor.Navigations
@for (int i = 0; i < 2; i++)
{
string target = "target" + @i;
string targetID = "#" + target;
<div id=@target @onclick="@((MouseEventArgs e)=>click(e, target))">Right click/Touch hold to open the ContextMenu </div>
<SfContextMenu @ref="component" Target=@targetID Items="@MenuItems">
<ContextMenuEvents OnOpen="OnOpen" Opened="Opened"></ContextMenuEvents>
</SfContextMenu>
}
@code
{
SfContextMenu component { set => components.Add(value); }
List<SfContextMenu> components = new List<SfContextMenu>();
SfContextMenu ContextMenuObj;
public bool isLeftClick = false;
private void click(MouseEventArgs args, string target)
{
this.isLeftClick = true;
int cmObj = Convert.ToInt32(target.Substring(target.Length - 1));
components[cmObj].Open(args.ClientY, args.ClientX);
}
public List<MenuItem> MenuItems = new List<MenuItem>
{
new MenuItem{ Text = "Cut" },
new MenuItem{ Text = "Copy" },
new MenuItem{ Text = "Paste" }
};
public void OnOpen(BeforeOpenCloseMenuEventArgs args)
{
if (!this.isLeftClick)
{
args.Cancel = true;
}
}
public void Opened(OpenCloseMenuEventArgs args)
{
this.isLeftClick = false;
}
}
<style>
#target0, #target1 {
border: 1px dashed;
height: 150px;
padding: 10px;
position: relative;
text-align: justify;
color: gray;
user-select: none;
}
</style>
|
@using Syncfusion.Blazor.Navigations
<div id="target">Right click/Touch hold to open the ContextMenu </div>
<SfContextMenu Target="#target" TValue="MenuItem">
<MenuItems>
<MenuItem Text="Cut"></MenuItem>
<MenuItem Text="Copy"></MenuItem>
<MenuItem Text="Paste"></MenuItem>
</MenuItems>
</SfContextMenu>
<div style="height:1000px"></div>
<style>
#target {
border: 1px dashed;
height: 150px;
padding: 10px;
position: relative;
text-align: justify;
color: gray;
user-select: none;
}
</style>
|