前台代码
<Grid ContextMenuOpening="Image_ContextMenuOpening">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="34"/>
</Grid.RowDefinitions>
<!--右键弹出菜单-->
<Grid.ContextMenu>
<ContextMenu>
<MenuItem Tag="{Binding FileFullPath}" Header="{Binding DeleteImage,Source={StaticResource string}}" Name="DeleteImage" Click="DeleteImage_Click"/>
</ContextMenu>
</Grid.ContextMenu>
</Grid>
后台代码
private void Image_ContextMenuOpening(object sender, ContextMenuEventArgs e)
{
Grid GridDrag = sender as Grid;
ContextMenu context = new ContextMenu();
int count = GridDrag.ContextMenu.Items.Count;
for (int i = 1; i < count; i++)
{
MenuItem m = GridDrag.ContextMenu.Items[i] as MenuItem;
if (m != null)
{
if (m.Name == "DeleteImage")
{
if (SystemINI.GetDeleteImageEnabled())
m.Visibility = Visibility.Visible;
else
m.Visibility = Visibility.Collapsed;
}
}
}
}
private void DeleteImage_Click(object sender, RoutedEventArgs e)
{
//操作
MenuItem item = sender as MenuItem;
string sPath = item.Tag.ToString();
}