我想在画布上的图像上删除longpress上的图像

时间:2016-06-13 07:02:43

标签: c# xaml canvas uwp

我使用下面给出的代码在画布上显示图像,现在我想删除长按该图像的显示图像。我尝试了上下文菜单,但它不起作用。请任何人告诉我我怎么做或正确使用contextmenu

private void Stickers1_SelectionChanged(object sender, SelectionChangedEventArgs e) {
    var selecteditem = e.AddedItems[0] as StickersImageListModel; 

    Stickers1.Visibility = Visibility.Collapsed;    

    // taking image from a list StickersImageListModel of images and bind with imageitem varaible    
    Image imageitem = new Image();    
    BitmapImage image = new BitmapImage(new System.Uri(selecteditem.Imageurl, UriKind.Absolute));    
    imageitem.Source = image;

    //Add the images on canvas    
    my_canvas.Children.Add(imageitem);    
    imageitem.AllowDrop = true;

    // DRag and drop the images on canvas   
    imageitem.ManipulationMode = ManipulationModes.All;    
    imageitem.ManipulationDelta += Drag_ManipulationDelta;    
    CompositeTransform ct = new CompositeTransform();    
    imageitem.RenderTransform = ct;   

    my_canvas.Visibility = Visibility.Visible;    
}

1 个答案:

答案 0 :(得分:0)

您可以将Holding事件用于图片。但是,您必须注意,桌面应用程序不会触发Holding事件,而是必须使用RightTapped事件。 如果您仅定位到移动应用,则可以使用举办活动

 //  imageitem.RightTapped += Imageitem_RightTapped;
            imageitem.Holding += Imageitem_Holding;
            imageitem.IsRightTapEnabled = true;
            imageitem.IsHoldingEnabled = true;

 private void Imageitem_RightTapped(object sender, RightTappedRoutedEventArgs e)
        {
            mycanvas.Children.Remove(sender as Image);
        }

        private void Imageitem_Holding(object sender, HoldingRoutedEventArgs e)
        {
            mycanvas.Children.Remove(sender as Image);
        }