|
| 1 | +using Microsoft.Maui.Controls; |
| 2 | +using Microsoft.Maui.Controls.Xaml; |
| 3 | + |
| 4 | +namespace Maui.Controls.Sample; |
| 5 | + |
| 6 | +[XamlCompilation(XamlCompilationOptions.Compile)] |
| 7 | +public partial class DragAndDropEventArgs : ContentView |
| 8 | +{ |
| 9 | + bool _emittedDragOver = false; |
| 10 | + public DragAndDropEventArgs() |
| 11 | + { |
| 12 | + InitializeComponent(); |
| 13 | + } |
| 14 | + |
| 15 | + void AddEvent(string name) |
| 16 | + { |
| 17 | + events.Text += $"{name},"; |
| 18 | + } |
| 19 | + |
| 20 | + void DragStarting(object sender, DragStartingEventArgs e) |
| 21 | + { |
| 22 | + _emittedDragOver = false; |
| 23 | + if (e.PlatformArgs is PlatformDragStartingEventArgs platformArgs) |
| 24 | + { |
| 25 | +#if IOS || MACCATALYST |
| 26 | + if (platformArgs.Sender is not null) |
| 27 | + AddEvent("DragStarting:" + nameof(platformArgs.Sender)); |
| 28 | + if (platformArgs.DragInteraction is not null) |
| 29 | + AddEvent("DragStarting:" + nameof(platformArgs.DragInteraction)); |
| 30 | + if (platformArgs.DragSession is not null) |
| 31 | + AddEvent("DragStarting:" + nameof(platformArgs.DragSession)); |
| 32 | +#elif ANDROID |
| 33 | + if (platformArgs.Sender is not null) |
| 34 | + AddEvent("DragStarting:" + nameof(platformArgs.Sender)); |
| 35 | + if (platformArgs.MotionEvent is not null) |
| 36 | + AddEvent("DragStarting:" + nameof(platformArgs.MotionEvent)); |
| 37 | +#elif WINDOWS |
| 38 | + if (platformArgs.Sender is not null) |
| 39 | + AddEvent("DragStarting:" + nameof(platformArgs.Sender)); |
| 40 | + if (platformArgs.DragStartingEventArgs is not null) |
| 41 | + AddEvent("DragStarting:" + nameof(platformArgs.DragStartingEventArgs)); |
| 42 | + AddEvent("DragStarting:" + nameof(platformArgs.Handled)); |
| 43 | +#endif |
| 44 | + } |
| 45 | + } |
| 46 | + |
| 47 | + void DropCompleted(object sender, DropCompletedEventArgs e) |
| 48 | + { |
| 49 | + if (e.PlatformArgs is PlatformDropCompletedEventArgs platformArgs) |
| 50 | + { |
| 51 | +#if IOS || MACCATALYST |
| 52 | + if (platformArgs.Sender is not null) |
| 53 | + AddEvent("DropCompleted:" + nameof(platformArgs.Sender)); |
| 54 | + if (platformArgs.DropInteraction is not null) |
| 55 | + AddEvent("DropCompleted:" + nameof(platformArgs.DropInteraction)); |
| 56 | + if (platformArgs.DropSession is not null) |
| 57 | + AddEvent("DropCompleted:" + nameof(platformArgs.DropSession)); |
| 58 | +#elif ANDROID |
| 59 | + if (platformArgs.Sender is not null) |
| 60 | + AddEvent("DropCompleted:" + nameof(platformArgs.Sender)); |
| 61 | + if (platformArgs.DragEvent is not null) |
| 62 | + AddEvent("DropCompleted:" + nameof(platformArgs.DragEvent)); |
| 63 | +#elif WINDOWS |
| 64 | + if (platformArgs.Sender is not null) |
| 65 | + AddEvent("DropCompleted:" + nameof(platformArgs.Sender)); |
| 66 | + if (platformArgs.DropCompletedEventArgs is not null) |
| 67 | + AddEvent("DropCompleted:" + nameof(platformArgs.DropCompletedEventArgs)); |
| 68 | +#endif |
| 69 | + } |
| 70 | + } |
| 71 | + |
| 72 | + void DragLeave(object sender, DragEventArgs e) |
| 73 | + { |
| 74 | + if (e.PlatformArgs is PlatformDragEventArgs platformArgs) |
| 75 | + { |
| 76 | +#if IOS || MACCATALYST |
| 77 | + if (platformArgs.Sender is not null) |
| 78 | + AddEvent("DragLeave:" + nameof(platformArgs.Sender)); |
| 79 | + if (platformArgs.DropInteraction is not null) |
| 80 | + AddEvent("DragLeave:" + nameof(platformArgs.DropInteraction)); |
| 81 | + if (platformArgs.DropSession is not null) |
| 82 | + AddEvent("DragLeave:" + nameof(platformArgs.DropSession)); |
| 83 | +#elif ANDROID |
| 84 | + if (platformArgs.Sender is not null) |
| 85 | + AddEvent("DragLeave:" + nameof(platformArgs.Sender)); |
| 86 | + if (platformArgs.DragEvent is not null) |
| 87 | + AddEvent("DragLeave:" + nameof(platformArgs.DragEvent)); |
| 88 | +#elif WINDOWS |
| 89 | + if (platformArgs.Sender is not null) |
| 90 | + AddEvent("DragLeave:" + nameof(platformArgs.Sender)); |
| 91 | + if (platformArgs.DragEventArgs is not null) |
| 92 | + AddEvent("DragLeave:" + nameof(platformArgs.DragEventArgs)); |
| 93 | + AddEvent("DragLeave:" + nameof(platformArgs.Handled)); |
| 94 | +#endif |
| 95 | + } |
| 96 | + } |
| 97 | + |
| 98 | + void DragOver(object sender, DragEventArgs e) |
| 99 | + { |
| 100 | + if (!_emittedDragOver) // This can generate a lot of noise, only add it once |
| 101 | + { |
| 102 | + if (e.PlatformArgs is PlatformDragEventArgs platformArgs) |
| 103 | + { |
| 104 | +#if IOS || MACCATALYST |
| 105 | + if (platformArgs.Sender is not null) |
| 106 | + AddEvent("DragOver:" + nameof(platformArgs.Sender)); |
| 107 | + if (platformArgs.DropInteraction is not null) |
| 108 | + AddEvent("DragOver:" + nameof(platformArgs.DropInteraction)); |
| 109 | + if (platformArgs.DropSession is not null) |
| 110 | + AddEvent("DragOver:" + nameof(platformArgs.DropSession)); |
| 111 | +#elif ANDROID |
| 112 | + if (platformArgs.Sender is not null) |
| 113 | + AddEvent("DragOver:" + nameof(platformArgs.Sender)); |
| 114 | + if (platformArgs.DragEvent is not null) |
| 115 | + AddEvent("DragOver:" + nameof(platformArgs.DragEvent)); |
| 116 | +#elif WINDOWS |
| 117 | + if (platformArgs.Sender is not null) |
| 118 | + AddEvent("DragOver:" + nameof(platformArgs.Sender)); |
| 119 | + if (platformArgs.DragEventArgs is not null) |
| 120 | + AddEvent("DragOver:" + nameof(platformArgs.DragEventArgs)); |
| 121 | +#endif |
| 122 | + } |
| 123 | + _emittedDragOver = true; |
| 124 | + } |
| 125 | + } |
| 126 | + |
| 127 | + void Drop(object sender, DropEventArgs e) |
| 128 | + { |
| 129 | + if (e.PlatformArgs is PlatformDropEventArgs platformArgs) |
| 130 | + { |
| 131 | +#if IOS || MACCATALYST |
| 132 | + if (platformArgs.Sender is not null) |
| 133 | + AddEvent("Drop:" + nameof(platformArgs.Sender)); |
| 134 | + if (platformArgs.DropInteraction is not null) |
| 135 | + AddEvent("Drop:" + nameof(platformArgs.DropInteraction)); |
| 136 | + if (platformArgs.DropSession is not null) |
| 137 | + AddEvent("Drop:" + nameof(platformArgs.DropSession)); |
| 138 | +#elif ANDROID |
| 139 | + if (platformArgs.Sender is not null) |
| 140 | + AddEvent("Drop:" + nameof(platformArgs.Sender)); |
| 141 | + if (platformArgs.DragEvent is not null) |
| 142 | + AddEvent("Drop:" + nameof(platformArgs.DragEvent)); |
| 143 | +#elif WINDOWS |
| 144 | + if (platformArgs.Sender is not null) |
| 145 | + AddEvent("Drop:" + nameof(platformArgs.Sender)); |
| 146 | + if (platformArgs.DragEventArgs is not null) |
| 147 | + AddEvent("Drop:" + nameof(platformArgs.DragEventArgs)); |
| 148 | +#endif |
| 149 | + } |
| 150 | + } |
| 151 | +} |
0 commit comments