1.启动Window的AllowDrop属性;即AllowDrop="True"。

2.添加Drop事件;即Drop="Window_Drop",当然事件名可以不用默认的而是用自定义的。PS:此处,除Drop事件外,我们还可以使用DragEnterDragOverDragLeave三个事件。

3.后台加事件的具体代码(见代码段)。

1 <Window x:Class="拖动文件到窗口显示文件路径.MainWindow"
2         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4         Title="MainWindow" Height="350" Width="525"
5         AllowDrop="True"
6         Drop="Window_Drop">
7     <Grid>        
8     </Grid>
9 </Window>
XAML

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-07
  • 2021-08-17
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-01-14
  • 2022-01-04
  • 2021-09-08
  • 2021-11-27
  • 2021-09-22
相关资源
相似解决方案