Created
November 7, 2021 18:32
-
-
Save CheetahChrome/57af345bee281b903560a0263d3f4eb2 to your computer and use it in GitHub Desktop.
WPF Drag And Drop for Files. Each Event at Miniumum
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void DNDEnter(object sender, DragEventArgs e) | |
{ | |
if (!e.Data.GetDataPresent(DataFormats.FileDrop) || | |
sender == e.Source) | |
{ | |
e.Effects = DragDropEffects.None; | |
} | |
} | |
private void DNDFeedback(object sender, GiveFeedbackEventArgs e) | |
{ | |
base.OnGiveFeedback(e); | |
Mouse.SetCursor(Cursors.Cross); | |
} | |
private void DNDDrop(object sender, DragEventArgs e) | |
{ | |
if (e.Data.GetDataPresent(DataFormats.FileDrop, true)) | |
{ | |
string[] droppedFilePaths = e.Data.GetData(DataFormats.FileDrop, true) as string[]; | |
foreach (var file in droppedFilePaths) | |
{ | |
var name = System.IO.Path.GetFileName(file); | |
this.Title = name; | |
ShowJSON(File.ReadAllText(file)); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment