</UserControl.ContextMenu>
</UserControl>
//在xaml用户控件中插手ContextMenu,并添加“删除”MenuItem
private void UserControl_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
{
menu.IsOpen = true;
}
//右键点击事件激发ContextMenu
private void Delete_Click(object sender, RoutedEventArgs e)
{
if (this.Tag != null)
{
WrapPanel Wp = VisualTreeHelper.GetParent(this) as WrapPanel;
if (Wp != null)
{
Wp.Children.Remove(this);
}
}
} //操作VisualTreeHelper找到控件的容器Wrappanel,,并删除