0

Edit: I Simplified the question because even the most basic application, is doing the same thing

<Window x:Class="WpfApplication1.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525" AllowDrop="True" >
    <Canvas DragEnter="Grid_DragEnter" Drop="Grid_Drop" AllowDrop="True" Name="C1">
        <Image Height="42" HorizontalAlignment="Left" Margin="27,28,0,0" Name="image1" Stretch="Fill" VerticalAlignment="Top" Width="42" Source="/WpfApplication1;component/Images/BackgroundMan.PNG" MouseDown="image1_MouseDown" AllowDrop="False" Canvas.Left="-15" Canvas.Top="-16" />
    </Canvas>
</Window>



namespace WpfApplication1
{
public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
    }

    private void image1_MouseDown(object sender, MouseButtonEventArgs e)
    {
        //added a breakpoint it does fire
        //C1 is the name of the canvas
        DragDrop.DoDragDrop(C1, sender, DragDropEffects.Move);
    }

    private void Grid_DragEnter(object sender, DragEventArgs e)
    {
         //added a breakPoint it never fires
        e.Effects = DragDropEffects.Move;
    }

    private void Grid_Drop(object sender, DragEventArgs e)
    {
        //added a breakPoint it never fires
        image1.Margin = new Thickness(e.GetPosition(this).X, e.GetPosition(this).Y, 0, 0);
    }

}

}

neither the DragEnter or the Drop events fire

Edit: I added a Window_Drop event, and this is what is accepting the Drop Event, Anyidea why this is, and how do I get the Canvas to accept it. And should I even care, I can work with that I think.

General Grey
  • 3,598
  • 2
  • 25
  • 32
  • may be you should set the AllowDrop property of the form to false. Is there a PreviewDragEnter event on the grid? can't remember :) if yes, try to add a handler to it – Samy Arous May 18 '12 at 00:10

2 Answers2

1

The events will fire if you set a Background brush.

<Canvas Name="C1" AllowDrop="True"
        DragEnter="Grid_DragEnter" Drop="Grid_Drop"
        Background="Transparent">
LPL
  • 16,827
  • 6
  • 51
  • 95
  • This sounds like It makes sense. The canvas background is none existent, therefore there is no surface to detect a drag enter. I will have to test this on tuesday, I am away from my desk and its a long weekend here. I will test it and mark as answer accordingly. – General Grey May 19 '12 at 14:24
  • That was the problem, not having a background defined meant I couldn't drag something onto it. Thanks. – General Grey May 22 '12 at 12:03
0

It's not entirely clear to me what you want to do, but setting AllowDrop to true on the image should cause your Grid_DragEnter event to fire if you click and drag on the image.