Skip to content

Commit 6ce79a3

Browse files
Merge pull request #3 from susmitha-sundar/master
Updated the WPF DragDrop sample for SeemlessDragDrop blog
2 parents f5521c4 + a7212c9 commit 6ce79a3

14 files changed

+113
-566
lines changed

WPF/App.config

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<configuration>
33
<startup>
4-
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6"/>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2"/>
55
</startup>
66
</configuration>

WPF/Behavior/DragAndDropBehavior.cs

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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+
}

WPF/DragandDropDemo_2010.csproj

-116
This file was deleted.

WPF/DragandDropDemo_2010.sln

-20
This file was deleted.

WPF/DragandDropDemo_2012.csproj

-116
This file was deleted.

WPF/DragandDropDemo_2012.sln

-20
This file was deleted.

0 commit comments

Comments
 (0)