WPF 精修篇 拖拽 DragDrop

WPF 实现拖拽

效果

WPF 精修篇 拖拽 DragDrop_第1张图片

   
        
            
            
            
        
        
        
            

    
     private void WrapPanel_Drop(object sender, DragEventArgs e)
        {
      
            var item = e.Data;
            object data = item.GetData(item.GetFormats()[0]);
            if (data is UIElement) 
            {
                send.Children.Remove(data as UIElement);
                accept.Children.Add(data as UIElement);
            }
        
        }

        private void WrapPanel_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            object item = e.Source;
            if (item is UIElement) 
            {
                DragDrop.DoDragDrop(item as UIElement, item, DragDropEffects.Move);
            }
        }

 

accept 一方的控件 需要加上  AllowDrop="True" 允许接收drop的数据

你可能感兴趣的:(WPF,WPF)