This repository has been archived by the owner on Dec 21, 2023. It is now read-only.
/
MainWindow.xaml.cs
107 lines (103 loc) · 2.94 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
using DevExpress.Xpf.Mvvm.DataAnnotations;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel.DataAnnotations;
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;
namespace colGeneration
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
MetadataLocator.Default = MetadataLocator.Create().AddMetadata(typeof(Customer), typeof(DataAnnotationsElement1Metadata));
ObservableCollection<Customer> customers = new ObservableCollection<Customer>();
for (int i = 1; i < 10; i++)
{
customers.Add(new Customer() { ID = i, Name = "Name" + i, Phone = "00-00-0" + i % 10, HiredAt = DateTime.Now.AddDays(-i) });
}
grid.ItemsSource = customers;
ObservableCollection<Customer2> customers2 = new ObservableCollection<Customer2>();
for (int i = 1; i < 10; i++)
{
customers2.Add(new Customer2() { ID = i, Name = "Name" + i, Phone = "00-00-0" + i % 10, HiredAt = DateTime.Now.AddDays(-i) });
}
grid2.ItemsSource = customers2;
}
}
public class DataAnnotationsElement1Metadata : IMetadataProvider<Customer>
{
void IMetadataProvider<Customer>.BuildMetadata(MetadataBuilder<Customer> builder)
{
builder.Property(p => p.ID).NumericMask("N0");
builder.Property(p => p.Name).DisplayFormatString("name is: {0}", true);
builder.Property(p => p.Phone).RegExMask(@"\d{2}-\d{2}-\d{2}");
builder.Property(p => p.HiredAt).DateTimeMask("dd/MM/yyyy");
}
}
public class Customer
{
public int ID
{
get;
set;
}
public string Name
{
get;
set;
}
public string Phone
{
get;
set;
}
public DateTime HiredAt
{
get;
set;
}
}
public class Customer2
{
[NumericMask(Mask = "N0")]
public int ID
{
get;
set;
}
[DisplayFormat(DataFormatString = "name is: {0}")]
public string Name
{
get;
set;
}
[RegExMask(Mask = @"\d{2}-\d{2}-\d{2}")]
public string Phone
{
get;
set;
}
[DateTimeMask(Mask = "dd/MM/yyyy")]
public DateTime HiredAt
{
get;
set;
}
}
}