/// <summary> /// Event handler for when an item is dropped on the <see cref="DropBorder"/>. /// </summary> private void DropBorder_Drop(object sender, global::Windows.UI.Xaml.DragEventArgs e) { this.ShowDragDropDetails(nameof(global::Windows.UI.Xaml.UIElement.Drop), e); this.ShowDropDetails(e); return; }
/// <summary> /// Event handler for when a drag operation enters the <see cref="DropBorder"/>. /// </summary> private void DropBorder_DragEnter(object sender, global::Windows.UI.Xaml.DragEventArgs e) { // We accept only one operation e.AcceptedOperation = DataPackageOperation.Copy; this.ShowDragDropDetails(nameof(global::Windows.UI.Xaml.UIElement.DragEnter), e); return; }
protected virtual void OnDrop(global::Windows.UI.Xaml.DragEventArgs e) { global::Windows.Foundation.Metadata.ApiInformation.TryRaiseNotImplemented("Windows.UI.Xaml.Controls.Control", "void Control.OnDrop(DragEventArgs e)"); }
protected virtual void OnDrop(global::Windows.UI.Xaml.DragEventArgs e) { }
/// <summary> /// Displays the contents of the given <see cref="global::Windows.UI.Xaml.DragEventArgs"/> after a drop occurs. /// </summary> /// <param name="args">The drop event arguments to display.</param> private async void ShowDropDetails(global::Windows.UI.Xaml.DragEventArgs args) { string title = "Last Drop Details"; string position = string.Empty; string details = string.Empty; this.DropDetailsTextBlock.Visibility = Visibility.Visible; this.DropDetailsImage.Visibility = Visibility.Collapsed; // Only one data format can be displayed at once. // Therefore, the order/priority here is used to determine which should be displayed. // It should be ordered most specific to least generally speaking. if (args.DataView.Contains(StandardDataFormats.ApplicationLink)) { title += " (ApplicationLink)"; var appLink = await args.DataView.GetApplicationLinkAsync(); details = appLink.ToString(); } else if (args.DataView.Contains(StandardDataFormats.Bitmap)) { title += " (Bitmap)"; var stream = await args.DataView.GetBitmapAsync(); var bitmapImage = new BitmapImage(); bitmapImage.SetSource(await stream.OpenReadAsync()); this.DropDetailsImage.Source = bitmapImage; this.DropDetailsImage.Visibility = Visibility.Visible; this.DropDetailsTextBlock.Visibility = Visibility.Collapsed; } else if (args.DataView.Contains(StandardDataFormats.Html)) { title += " (Html)"; var html = await args.DataView.GetHtmlFormatAsync(); details = html; } else if (args.DataView.Contains(StandardDataFormats.Rtf)) { title += " (Rtf)"; var rtf = await args.DataView.GetRtfAsync(); details = rtf; } else if (args.DataView.Contains(StandardDataFormats.StorageItems)) { title += " (StorageItems)"; var items = await args.DataView.GetStorageItemsAsync(); if (items.Count > 0) { // Only use the first item foreach (IStorageItem item in items) { var file = item as StorageFile; if (file != null) { details += "Name: " + file.Name + Environment.NewLine; details += "DisplayName: " + file.DisplayName + Environment.NewLine; //details += "DisplayType: " + file.DisplayType + Environment.NewLine; details += "ContentType: " + file.ContentType + Environment.NewLine; details += "Path: " + file.Path; } } } } else if (args.DataView.Contains(StandardDataFormats.UserActivityJsonArray)) { title += " (UserActivityJsonArray)"; // TODO } else if (args.DataView.Contains(StandardDataFormats.Uri)) { title += " (Uri)"; var uri = await args.DataView.GetUriAsync(); details = uri.ToString(); } else if (args.DataView.Contains(StandardDataFormats.WebLink)) { title += " (WebLink)"; var webLink = await args.DataView.GetWebLinkAsync(); details = webLink.ToString(); } else if (args.DataView.Contains(StandardDataFormats.Text)) { title += " (Text)"; var text = await args.DataView.GetTextAsync(); details = text; } // Determine the drop position var pos = args.GetPosition(this.DropBorder); position = "(" + pos.X.ToString("0.00") + ", " + pos.Y.ToString("0.00") + ")"; this.DropTitleTextBlock.Text = title ?? string.Empty; this.DropPositionTextBlock.Text = position ?? string.Empty; this.DropDetailsTextBlock.Text = details ?? string.Empty; return; }
/// <summary> /// Displays the contents of the given <see cref="global::Windows.UI.Xaml.DragEventArgs"/> for any drag/drop event. /// </summary> /// <param name="eventName">The name of the event to display.</param> /// <param name="args">The event arguments to display.</param> private void ShowDragDropDetails(string eventName, global::Windows.UI.Xaml.DragEventArgs args) { // Determine the standard formats var standardDataFormats = string.Empty; var sep = Environment.NewLine; if (args.DataView.Contains(StandardDataFormats.ApplicationLink)) { standardDataFormats += nameof(StandardDataFormats.ApplicationLink) + sep; } if (args.DataView.Contains(StandardDataFormats.Bitmap)) { standardDataFormats += nameof(StandardDataFormats.Bitmap) + sep; } if (args.DataView.Contains(StandardDataFormats.Html)) { standardDataFormats += nameof(StandardDataFormats.Html) + sep; } if (args.DataView.Contains(StandardDataFormats.Rtf)) { standardDataFormats += nameof(StandardDataFormats.Rtf) + sep; } if (args.DataView.Contains(StandardDataFormats.StorageItems)) { standardDataFormats += nameof(StandardDataFormats.StorageItems) + sep; } if (args.DataView.Contains(StandardDataFormats.Text)) { standardDataFormats += nameof(StandardDataFormats.Text) + sep; } if (args.DataView.Contains(StandardDataFormats.UserActivityJsonArray)) { standardDataFormats += nameof(StandardDataFormats.UserActivityJsonArray) + sep; } if (args.DataView.Contains(StandardDataFormats.Uri)) { standardDataFormats += nameof(StandardDataFormats.Uri) + sep; } if (args.DataView.Contains(StandardDataFormats.WebLink)) { standardDataFormats += nameof(StandardDataFormats.WebLink) + sep; } if (standardDataFormats.EndsWith(sep)) { standardDataFormats = standardDataFormats.Substring(0, standardDataFormats.Length - sep.Length); } var eventDetails = new EventDetails() { EventName = eventName ?? string.Empty, AvailableFormats = string.Join(Environment.NewLine, args.DataView.AvailableFormats) ?? string.Empty, AvailableStdFormats = standardDataFormats, RequestedOperation = args.DataView.RequestedOperation.ToString(), Timestamp = DateTimeOffset.Now.ToString("HH:mm:ss.fff") }; switch (eventName) { case nameof(UIElement.DragStarting): { eventDetails.EventBackground = this.DragStartingBrush; break; } case nameof(UIElement.DragEnter): { eventDetails.EventBackground = this.DragEnterBrush; break; } case nameof(UIElement.DragLeave): { eventDetails.EventBackground = this.DragLeaveBrush; break; } case nameof(UIElement.DragOver): { eventDetails.EventBackground = this.DragOverBrush; break; } case nameof(UIElement.Drop): { eventDetails.EventBackground = this.DropBrush; break; } case nameof(UIElement.DropCompleted): { eventDetails.EventBackground = this.DropCompletedBrush; break; } } this.AddToDragDropEvents(eventDetails); return; }