This repository has been archived by the owner on Sep 25, 2023. It is now read-only.
/
MainWindow.xaml.cs
88 lines (76 loc) · 3.04 KB
/
MainWindow.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Input;
using System.Collections.ObjectModel;
using DevExpress.Xpf.Grid;
namespace TileLayoutControlDescendant
{
public partial class MainWindow : Window
{
int handler = GridControl.InvalidRowHandle;
Point point;
public MainWindow()
{
InitializeComponent();
desc.ItemsSource = DataHelper.GetData1();
gridControl1.ItemsSource = DataHelper.GetData2();
}
private void Dumping()
{
handler = GridControl.InvalidRowHandle;
point = new Point(-1000, -1000);
}
private void gridControl1_Drop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent("DragDropDataDG"))
{
((sender as GridControl).ItemsSource as ObservableCollection<ExampleObject>).Add((ExampleObject)e.Data.GetData("DragDropDataDG"));
}
}
private void gridControl1_PreviewMouseDown(object sender, MouseButtonEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
point = e.GetPosition(null);
GridControl grid = sender as GridControl;
GridViewHitInfoBase info;
CardView view = grid.View as CardView;
info = view.CalcHitInfo(e.OriginalSource as DependencyObject);
if (info.RowHandle != GridControl.InvalidRowHandle)
{
handler = info.RowHandle;
e.Handled = true;
}
}
}
private void gridControl1_MouseMove(object sender, MouseEventArgs e)
{
GridControl grid = sender as GridControl;
GridViewBase view = grid.View as GridViewBase;
Point mousePos = e.GetPosition(null);
if (e.LeftButton != MouseButtonState.Pressed) return;
if (handler == GridControl.InvalidRowHandle) return;
Rect rect = new Rect(
(point.X - SystemParameters.MinimumHorizontalDragDistance),
(point.Y - (int)SystemParameters.MinimumVerticalDragDistance),
SystemParameters.MinimumHorizontalDragDistance * 2,
SystemParameters.MinimumVerticalDragDistance * 2);
if (!rect.Contains(mousePos))
{
DataObject dragData = new DataObject("DragDropDataGD", (view.GetRowElementByRowHandle(handler).DataContext as RowData).Row);
Dumping();
DragDrop.DoDragDrop(grid, dragData, DragDropEffects.Copy);
}
}
private void desc_Drop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent("DragDropDataGD"))
{
TileLayoutCntrlDescendant cntrl = sender as TileLayoutCntrlDescendant;
(cntrl.ItemsSource as ObservableCollection<ExampleObject>).Add((ExampleObject)e.Data.GetData("DragDropDataGD"));
}
}
}
}