|
| 1 | +using Microsoft.Xaml.Behaviors; |
| 2 | +using Syncfusion.UI.Xaml.Grid; |
| 3 | +using Syncfusion.UI.Xaml.TreeGrid; |
| 4 | +using System; |
| 5 | +using System.Collections; |
| 6 | +using System.Collections.Generic; |
| 7 | +using System.Collections.ObjectModel; |
| 8 | +using System.Linq; |
| 9 | +using System.Text; |
| 10 | +using System.Threading.Tasks; |
| 11 | + |
| 12 | +namespace DragandDropDemo |
| 13 | +{ |
| 14 | + public class DragAndDropBehavior:Behavior<MainWindow> |
| 15 | + { |
| 16 | + protected override void OnAttached() |
| 17 | + { |
| 18 | + base.OnAttached(); |
| 19 | + //Uncomment these events for Drag Drop customization |
| 20 | + //AssociatedObject.firstGrid.RowDragDropController.DragStart += RowDragDropController_DragStart; |
| 21 | + //AssociatedObject.firstGrid.RowDragDropController.DragOver += RowDragDropController_DragOver; |
| 22 | + //AssociatedObject.firstGrid.RowDragDropController.Drop += RowDragDropController_Drop; |
| 23 | + //AssociatedObject.firstGrid.RowDragDropController.Dropped += RowDragDropController_Dropped; |
| 24 | + } |
| 25 | + |
| 26 | + private void RowDragDropController_Dropped(object sender, GridRowDroppedEventArgs e) |
| 27 | + { |
| 28 | + ObservableCollection<object> draggingRecords = new ObservableCollection<object>(); |
| 29 | + |
| 30 | + draggingRecords = e.Data.GetData("Records") as ObservableCollection<object>; |
| 31 | + |
| 32 | + var items = draggingRecords[0] as UserInfo; |
| 33 | + |
| 34 | + var records = AssociatedObject.firstGrid.View.Records.ToList(); |
| 35 | + |
| 36 | + IList collection = AssociatedObject.firstGrid.ItemsSource as IList; |
| 37 | + |
| 38 | + for (int i = 0; i < records.Count; i++) |
| 39 | + { |
| 40 | + |
| 41 | + var orderData = records[i].Data as UserInfo; |
| 42 | + if (orderData.UserId == items.UserId) |
| 43 | + { |
| 44 | + collection.Remove(items); |
| 45 | + collection.Insert(i, orderData); |
| 46 | + } |
| 47 | + |
| 48 | + } |
| 49 | + AssociatedObject.firstGrid.ItemsSource = collection; |
| 50 | + } |
| 51 | + |
| 52 | + private void RowDragDropController_Drop(object sender, GridRowDropEventArgs e) |
| 53 | + { |
| 54 | + var record = e.DraggingRecords[0] as UserInfo; |
| 55 | + var dropPosition = e.DropPosition.ToString(); |
| 56 | + |
| 57 | + if (dropPosition == "DropAbove") |
| 58 | + e.Handled = true; |
| 59 | + |
| 60 | + if (record != null && record.UserId == 1010) |
| 61 | + e.Handled = true; |
| 62 | + } |
| 63 | + |
| 64 | + |
| 65 | + private void RowDragDropController_DragOver(object sender, GridRowDragOverEventArgs e) |
| 66 | + { |
| 67 | + e.ShowDragUI = false; |
| 68 | + } |
| 69 | + |
| 70 | + private void RowDragDropController_DragStart(object sender, GridRowDragStartEventArgs e) |
| 71 | + { |
| 72 | + var record = e.DraggingRecords[0] as UserInfo; |
| 73 | + if(record != null && record.UserId == 1005) |
| 74 | + { |
| 75 | + e.Handled = true; |
| 76 | + } |
| 77 | + } |
| 78 | + |
| 79 | + protected override void OnDetaching() |
| 80 | + { |
| 81 | + AssociatedObject.firstGrid.RowDragDropController.DragStart -= RowDragDropController_DragStart; |
| 82 | + AssociatedObject.firstGrid.RowDragDropController.DragOver -= RowDragDropController_DragOver; |
| 83 | + AssociatedObject.firstGrid.RowDragDropController.Drop -= RowDragDropController_Drop; |
| 84 | + AssociatedObject.firstGrid.RowDragDropController.Dropped -= RowDragDropController_Dropped; |
| 85 | + base.OnDetaching(); |
| 86 | + } |
| 87 | + } |
| 88 | +} |
0 commit comments