Why doesn't WPF Canvas alow drop?

后端 未结 2 854
星月不相逢
星月不相逢 2021-01-17 21:59

I have the following XAML for the main window:



        
相关标签:
2条回答
  • 2021-01-17 22:35

    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;
    
    0 讨论(0)
  • 2021-01-17 22:40

    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>
    
    0 讨论(0)
提交回复
热议问题