public async Task SendDrop(DropEventArgs args) { if (!AllowDrop) { return; } DropCommand?.Execute(DropCommandParameter); Drop?.Invoke(this, args); if (!args.Handled) { var dataView = args.Data; var internalProperties = dataView.PropertiesInternal; VisualElement dragSource = null; ImageSource sourceTarget = await dataView.GetImageAsync(); string text = await dataView.GetTextAsync(); if (internalProperties.ContainsKey("DragSource")) { dragSource = (VisualElement)internalProperties["DragSource"]; if (sourceTarget == null && dragSource is IImageElement imageElement) { sourceTarget = imageElement.Source; } if (String.IsNullOrWhiteSpace(text)) { text = dragSource.GetStringValue(); } } if (Parent is IImageElement && sourceTarget == null) { sourceTarget = text; } if (Parent is Image image) { image.Source = sourceTarget; } else if (Parent is ImageButton ib) { ib.Source = sourceTarget; } else if (Parent is Button b) { b.ImageSource = sourceTarget; } Parent?.TrySetValue(text); } }
void DropGestureRecognizer_Drop(System.Object sender, Xamarin.Forms.DropEventArgs e) { StackLayout sl = ((StackLayout)(sender as DropGestureRecognizer).Parent); sl.BackgroundColor = Color.LightGray; // add new box to the stack var btn = new Button(); btn.BackgroundColor = (Color)e.Data.Properties["Color"]; sl.Children.Add(btn); btn.Clicked += ButtonRemove_Clicked; }
void DoneDropGestureRecognizer_Drop(System.Object sender, Xamarin.Forms.DropEventArgs e) { var id = (string)e.Data.Properties["Id"]; ViewModel.DoneDrop(id); }
private void DropGestureRecognizer_Drop_Collection(System.Object sender, Xamarin.Forms.DropEventArgs e) { // We handle reordering login in our view model e.Handled = true; }