I have the following XAML for the main window:
This works like a charm! In code you would want to do something such as:
Canvas myCanvas = new Canvas();
myCanvas.AllowDrop = true;
myCanvas.Background = System.Windows.Media.Brushes.Transparent;
By default, Canvas
has no background so hit-testing is not picking up that the cursor is over the Canvas
element, but is instead bubbling up to the Grid
or Window
which don't allow drop. Set the background to Transparent
as follows and it should work:
<Window x:Class="ImageViewer.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="398" Width="434">
<Grid>
<Canvas AllowDrop="True" Background="Transparent" />
</Grid>
</Window>