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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Tango.Core;
using Tango.Core.Commands;
using Tango.DragAndDrop;
namespace Tango.UITests
{
public class Person : ExtendedObject
{
public String FirstName { get; set; }
public String LastName { get; set; }
private int _index;
public int Index
{
get { return _index; }
set { _index = value; RaisePropertyChangedAuto(); }
}
public int Age { get; set; }
}
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public ObservableCollection<Person> Persons
{
get { return (ObservableCollection<Person>)GetValue(PersonsProperty); }
set { SetValue(PersonsProperty, value); }
}
public static readonly DependencyProperty PersonsProperty =
DependencyProperty.Register("Persons", typeof(ObservableCollection<Person>), typeof(MainWindow), new PropertyMetadata(null));
public RelayCommand<DropEventArgs> DropCommand { get; set; }
public MainWindow()
{
Persons = new ObservableCollection<Person>();
for (int i = 1; i < 10; i++)
{
Persons.Add(new Person()
{
Age = i,
FirstName = "Roy " + i.ToString(),
LastName = "Ben Shabat " + i.ToString(),
Index = i,
});
}
DropCommand = new RelayCommand<DropEventArgs>(OnDrop);
InitializeComponent();
}
private void OnDrop(DropEventArgs e)
{
var dragPerson = (e.Draggable as FrameworkElement).DataContext as Person;
var dropPerson = (e.Droppable as FrameworkElement).DataContext as Person;
Debug.WriteLine(dragPerson.FirstName + " dropped on " + dropPerson.FirstName);
int dragIndex = dragPerson.Index;
dragPerson.Index = dropPerson.Index;
dropPerson.Index = dragIndex;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show("Done");
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
Persons.Add(new Person()
{
FirstName = "New",
LastName = "Person",
Age = 200,
Index = 0
});
}
}
}
|