-
Notifications
You must be signed in to change notification settings - Fork 1
/
Window1.xaml.cs
61 lines (60 loc) · 2.09 KB
/
Window1.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
using DevExpress.Xpf.Core;
using DevExpress.Xpf.Grid;
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
namespace EditorsDesignTime {
public partial class Window1 : Window {
public Window1() {
InitializeComponent();
List<TestData> list = new List<TestData>();
for (int i = 0; i < 100; i++)
list.Add(new TestData() { Editor = GetEditorType(i), Value = GetEditValue(i) });
grid.ItemsSource = list;
}
string GetEditorType(int index) {
switch (index % 6) {
case 0:
return "booleanEditor";
case 1:
return "buttonEditor";
case 2:
return "comboboxEditor";
case 3:
return "dateEditor";
case 4:
return "textEditor";
default:
return string.Empty;
}
}
object GetEditValue(int index) {
switch (index % 6) {
case 0:
return index % 2 == 0;
case 1:
return "button edit " + index;
case 2:
return index % 2 == 0 ? Alignment.Far : Alignment.Near;
case 3:
return DateTime.Today.AddDays(index);
case 4:
return "text " + index;
default:
return string.Empty;
}
}
}
public class TestData {
public string Editor { get; set; }
public object Value { get; set; }
}
public class EditorTemplateSelector : DataTemplateSelector {
public override DataTemplate SelectTemplate(object item, DependencyObject container) {
GridCellData data = (GridCellData)item;
var dataItem = data.RowData.Row as TestData;
return string.IsNullOrEmpty(dataItem.Editor) ? null : (DataTemplate)((FrameworkElement)container).FindResource(dataItem.Editor);
}
}
}