/
XamGridView.cs
194 lines (173 loc) · 5.45 KB
/
XamGridView.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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
using System;
using System.Collections;
using Xamarin.Forms;
namespace XamGridViewForms.Controls
{
public class XamGridView:Xamarin.Forms.View
{
/// <summary>
/// Initializes a new instance of the <see cref="XamGridView"/> class.
/// </summary>
public XamGridView()
{
SelectionEnabled = true;
}
//
// Static Fields
//
/// <summary>
/// The items source property
/// </summary>
public static readonly BindableProperty ItemsSourceProperty = BindableProperty.Create ("ItemsSource", typeof (IEnumerable), typeof (XamGridView), null, BindingMode.OneWay, null, null, null, null);
/// <summary>
/// The item template property
/// </summary>
public static readonly BindableProperty ItemTemplateProperty = BindableProperty.Create ("ItemTemplate", typeof (DataTemplate), typeof (XamGridView), null, BindingMode.OneWay, null, null, null, null);
/// <summary>
/// The row spacing property
/// </summary>
public static readonly BindableProperty RowSpacingProperty = BindableProperty.Create ("RowSpacing", typeof (double), typeof (XamGridView), 0.0, BindingMode.OneWay, null, null, null, null);
/// <summary>
/// The column spacing property
/// </summary>
public static readonly BindableProperty ColumnSpacingProperty = BindableProperty.Create ("ColumnSpacing", typeof (double), typeof (XamGridView), 0.0, BindingMode.OneWay, null, null, null, null);
///// <summary>
///// The item width property
///// </summary>
//public static readonly BindableProperty ItemWidthProperty = BindableProperty.Create ("ItemWidth", typeof (double), typeof (XamGridView), 100.0, BindingMode.OneWay, null, null, null, null);
///// <summary>
///// The item height property
///// </summary>
//public static readonly BindableProperty ItemHeightProperty = BindableProperty.Create ("ItemHeight", typeof (double), typeof (XamGridView), 100.0, BindingMode.OneWay, null, null, null, null);
/// <summary>
/// The padding property
/// </summary>
public static readonly BindableProperty PaddingProperty = BindableProperty.Create<XamGridView, Thickness> (view => view.Padding, new Thickness (0), BindingMode.OneWay);
/// <summary>
/// The column spacing property
/// </summary>
public static readonly BindableProperty NoOfColumnsProperty = BindableProperty.Create ("NoOfColumns", typeof (int), typeof (XamGridView), 0, BindingMode.OneWay, null, null, null, null);
//
// Properties
//
/// <summary>
/// Gets or sets the items source.
/// </summary>
/// <value>The items source.</value>
public IEnumerable ItemsSource {
get {
return (IEnumerable)base.GetValue (XamGridView.ItemsSourceProperty);
}
set {
base.SetValue (XamGridView.ItemsSourceProperty, value);
}
}
/// <summary>
/// Gets or sets the item template.
/// </summary>
/// <value>The item template.</value>
public DataTemplate ItemTemplate {
get {
return (DataTemplate)base.GetValue (XamGridView.ItemTemplateProperty);
}
set {
base.SetValue (XamGridView.ItemTemplateProperty, value);
}
}
/// <summary>
/// Gets or sets the row spacing.
/// </summary>
/// <value>The row spacing.</value>
public double RowSpacing {
get {
return (double)base.GetValue (XamGridView.RowSpacingProperty);
}
set {
base.SetValue (XamGridView.RowSpacingProperty, value);
}
}
/// <summary>
/// Gets or sets the column spacing.
/// </summary>
/// <value>The column spacing.</value>
public double ColumnSpacing {
get {
return (double)base.GetValue (XamGridView.ColumnSpacingProperty);
}
set {
base.SetValue (XamGridView.ColumnSpacingProperty, value);
}
}
/// <summary>
/// Gets or sets the column spacing.
/// </summary>
/// <value>The column spacing.</value>
public int NoOfColumns {
get {
return (int)base.GetValue (XamGridView.NoOfColumnsProperty);
}
set {
base.SetValue (XamGridView.NoOfColumnsProperty, value);
}
}
///// <summary>
///// Gets or sets the width of the item.
///// </summary>
///// <value>The width of the item.</value>
//public double ItemWidth {
// get {
// return (double)base.GetValue (XamGridView.ItemWidthProperty);
// }
// set {
// base.SetValue (XamGridView.ItemWidthProperty, value);
// }
//}
///// <summary>
///// Gets or sets the height of the item.
///// </summary>
///// <value>The height of the item.</value>
//public double ItemHeight {
// get {
// return (double)base.GetValue (XamGridView.ItemHeightProperty);
// }
// set {
// base.SetValue (XamGridView.ItemHeightProperty, value);
// }
//}
/// <summary>
/// Gets or sets the padding.
/// </summary>
/// <value>The padding.</value>
public Thickness Padding {
get {
return (Thickness)base.GetValue (PaddingProperty);
}
set {
base.SetValue (PaddingProperty, value);
}
}
/// <summary>
/// Occurs when item is selected.
/// </summary>
public event EventHandler<object> ItemSelected;
/// <summary>
/// Invokes the item selected event.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="item">Item.</param>
public void InvokeItemSelectedEvent (object sender, object item)
{
if (this.ItemSelected != null) {
this.ItemSelected.Invoke (sender, item);
}
}
/// <summary>
/// Gets or sets a value indicating whether [selection enabled].
/// </summary>
/// <value><c>true</c> if [selection enabled]; otherwise, <c>false</c>.</value>
public bool SelectionEnabled {
get;
set;
}
}
}