适用环境:Windows 10 X64
修改注册表:
计算机HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionPoliciesSystemEnableLUA
的值为0
<TextBox Grid.Row="0" Grid.Column="0" AllowDrop="True" PreviewDragEnter="WhenPreviewDragOver" PreviewDragOver="WhenPreviewDragOver" Drop="WhenFileDrop" Background="Pink" Text="TextBox"></TextBox>
private void WhenPreviewDragOver(object sender, DragEventArgs e) { e.Effects = DragDropEffects.All; e.Handled = true; } private void WhenFileDrop(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.FileDrop, false)) { string[] filePaths = e.Data.GetData(DataFormats.FileDrop) as string[]; if (filePaths != null) { MessageBox.Show(string.Join(Environment.NewLine, filePaths)); } } }