This repository has been archived by the owner on Dec 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.xaml.cs
168 lines (150 loc) · 5.37 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
// Developer Express Code Central Example:
// How to serialize custom properties with a custom type using the CreateContentPropertyValue event
//
// This example demonstrates how to serialize and deserialize custom properties
// with a custom type. If a custom property is null when the deserialization
// process is invoked, it's necessary to handle the
// DXSerializer.CreateContentPropertyValue event. In the CreateContentPropertyValue
// event handler, create a new instance of a custom type and assign it to the
// XtraCreateContentPropertyValueEventArgs.SomeCustomProperty property.
//
// You can find sample updates and versions for different programming languages here:
// http://www.devexpress.com/example=T159099
using DevExpress.Data;
using DevExpress.Utils.Serializing;
using DevExpress.Utils.Serializing.Helpers;
using DevExpress.Xpf.Core.Serialization;
using DevExpress.Xpf.Editors;
using DevExpress.Xpf.Grid;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
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 WpfApplication58
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
ObservableCollection<Customer> customers = new ObservableCollection<Customer>();
for (int i = 1; i < 30; i++)
{
customers.Add(new Customer() { ID = i, Name = "Name" + i });
}
grid.ItemsSource = customers;
grid.Columns["Name"].AddHandler(DXSerializer.CreateCollectionItemEvent, new XtraCreateCollectionItemEventHandler(OnCreateCollectionItem));
grid.Columns["Name"].AddHandler(DXSerializer.ClearCollectionEvent, new XtraItemRoutedEventHandler(OnClearCollectionItem));
nameColumn.SomeCollection = new ObservableCollection<CustomObject>();
}
void OnClearCollectionItem(object sender, XtraItemRoutedEventArgs e)
{
((ObservableCollection<CustomObject>)e.Collection).Clear();
}
void OnCreateCollectionItem(object sender, XtraCreateCollectionItemEventArgs e)
{
CustomObject item = new CustomObject();
((ObservableCollection<CustomObject>)e.Collection).Add(item);
e.CollectionItem = item;
}
private void loadButton_Click(object sender, RoutedEventArgs e)
{
grid.RestoreLayoutFromXml("..\\..\\layout.xml");
}
private void saveButton_Click(object sender, RoutedEventArgs e)
{
grid.SaveLayoutToXml("..\\..\\layout.xml");
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
grid.RestoreLayoutFromXml("..\\..\\layout.xml");
}
private void addButton_Click(object sender, RoutedEventArgs e)
{
CustomObject item = new CustomObject() { ItemID = propATextBox.Text, ItemValue = propBTextBox.Text };
nameColumn.SomeCollection.Add(item);
}
private void clearButton_Click(object sender, RoutedEventArgs e)
{
nameColumn.SomeCollection.Clear();
}
}
public class MyGridColumn : GridColumn
{
[XtraSerializableProperty(XtraSerializationVisibility.Collection, true, false, true)]
public ObservableCollection<CustomObject> SomeCollection
{
get { return (ObservableCollection<CustomObject>)GetValue(SomeCollectionProperty); }
set { SetValue(SomeCollectionProperty, value); }
}
public static readonly DependencyProperty SomeCollectionProperty =
DependencyProperty.Register("SomeCollection", typeof(ObservableCollection<CustomObject>), typeof(MyGridColumn), null);
}
public class CustomObject : INotifyPropertyChanged
{
string itemID;
string itemValue;
[XtraSerializableProperty]
public string ItemID
{
get
{
return itemID;
}
set
{
itemID = value;
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs("ItemID"));
}
}
[XtraSerializableProperty]
public string ItemValue
{
get
{
return itemValue;
}
set
{
itemValue = value;
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs("PropertyB"));
}
}
public event PropertyChangedEventHandler PropertyChanged;
public void RaisePropertyChanged(string propertyName)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
public class Customer
{
public int ID
{
get;
set;
}
public string Name
{
get;
set;
}
}
}