-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathPopupPicker.xaml.cs
267 lines (235 loc) · 10 KB
/
PopupPicker.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
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
#region Copyright Syncfusion Inc. 2001-2024.
// Copyright Syncfusion Inc. 2001-2024. All rights reserved.
// Use of this code is subject to the terms of our license.
// A copy of the current license can be obtained at any time by e-mailing
// licensing@syncfusion.com. Any infringement will be prosecuted under
// applicable laws.
#endregion
using Common;
using Syncfusion.UI.Xaml.Controls.Input;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.Foundation.Metadata;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
namespace Input.Picker
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class PopupPicker : SampleLayout
{
bool isvaluechange;
ObservableCollection<object> todaycollection = new ObservableCollection<object>();
public PopupPicker()
{
this.InitializeComponent();
startdate.Closed += Startdate_OnPopUpClosed;
enddate.Closed += Enddate_OnPopUpClosed;
startdate.Opened += Startdate_DialogOpened;
enddate.Opened += Startdate_DialogOpened;
startdate.CancelButtonClicked += Startdate_CancelButtonClicked;
enddate.CancelButtonClicked += Enddate_CancelButtonClicked;
startdate.OkButtonClicked += startdate_OkButtonClicked;
enddate.OkButtonClicked += enddate_OkButtonClicked;
enddate.CancelButtonClicked += Enddate_CancelButtonClicked;
this.DataContext = new ViewModel();
startdatetxt.Text = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(DateTime.Now.Date.Month).Substring(0, 3) + " " + DateTime.Now.Day.ToString() + " " + DateTime.Now.Year.ToString();
enddatetxt.Text = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(DateTime.Now.Date.Month).Substring(0, 3) + " " + DateTime.Now.Day.ToString() + " " + DateTime.Now.Year.ToString();
//Select today dates
todaycollection.Add(CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(DateTime.Now.Date.Month).Substring(0, 3));
if (DateTime.Now.Date.Day < 10)
todaycollection.Add("0" + DateTime.Now.Date.Day);
else
todaycollection.Add(DateTime.Now.Date.Day.ToString());
todaycollection.Add(DateTime.Now.Date.Year.ToString());
if (ApiInformation.IsTypePresent("Windows.Phone.UI.Input.HardwareButtons"))
{
stack.HorizontalAlignment = HorizontalAlignment.Center;
startdate.Width = 280;
startdate.Height = 300;
enddate.Width = 280;
enddate.Height = 300;
}
//startdatetxt.Text = GetStringfromCollection((this.DataContext as ViewModel).StartDate);
//enddatetxt.Text = GetStringfromCollection((this.DataContext as ViewModel).EndDate);
}
private void Startdate_DialogOpened(object sender, RoutedEventArgs e)
{
isvaluechange = false;
}
private void Enddate_CancelButtonClicked(object source, SelectionChangedEventArgs args)
{
isvaluechange = true;
(this.DataContext as ViewModel).EndDate = GetCollectionfromstring(enddatetxt.Text);
}
private void Startdate_CancelButtonClicked(object source, SelectionChangedEventArgs args)
{
isvaluechange = true;
(this.DataContext as ViewModel).StartDate = GetCollectionfromstring(startdatetxt.Text);
}
private void Startdate_OnPopUpClosed(object sender, RoutedEventArgs e)
{
if (!isvaluechange)
{
if (string.IsNullOrEmpty(startdatetxt.Text))
{
(this.DataContext as ViewModel).StartDate = todaycollection;
}
else
{
(this.DataContext as ViewModel).StartDate = GetCollectionfromstring(startdatetxt.Text);
}
}
}
private void Enddate_OnPopUpClosed(object sender, RoutedEventArgs e)
{
if (!isvaluechange)
{
if (string.IsNullOrEmpty(enddatetxt.Text))
{
(this.DataContext as ViewModel).EndDate = todaycollection;
}
else
{
(this.DataContext as ViewModel).EndDate = GetCollectionfromstring(enddatetxt.Text);
}
}
}
private void Button_Click(object sender, RoutedEventArgs e)
{
startdate.IsOpen = true;
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
enddate.IsOpen = true;
}
public override void Dispose()
{
(this.DataContext as ViewModel).StartDate.Clear();
(this.DataContext as ViewModel).StartDate = null;
(this.DataContext as ViewModel).EndDate.Clear();
(this.DataContext as ViewModel).StartDate = null;
todaycollection.Clear();
todaycollection = null;
startdate.Closed -= Startdate_OnPopUpClosed;
enddate.Closed -= Enddate_OnPopUpClosed;
startdate.CancelButtonClicked -= Startdate_CancelButtonClicked;
enddate.CancelButtonClicked -= Enddate_CancelButtonClicked;
startdate.OkButtonClicked -= startdate_OkButtonClicked;
enddate.OkButtonClicked -= enddate_OkButtonClicked;
enddate.CancelButtonClicked -= Enddate_CancelButtonClicked;
startdate.Dispose();
enddate.Dispose();
this.DataContext = null;
startdate = null;
enddate = null;
base.Dispose();
}
#region get Collections and String
ObservableCollection<object> GetCollectionfromList(IList dates)
{
ObservableCollection<object> items = new ObservableCollection<object>();
foreach (var item in dates)
{
items.Add(item);
}
return items;
}
string GetStringfromCollection(ICollection collection)
{
string dates = string.Empty;
foreach (var item in collection)
{
dates += item + " ";
}
return dates;
}
ObservableCollection<object> GetCollectionfromstring(string text)
{
if (!string.IsNullOrEmpty(text))
{
var str = text.Split(' ').Where(s => !string.IsNullOrEmpty(s));
ObservableCollection<object> items = new ObservableCollection<object>();
foreach (var item in str)
{
items.Add(item);
}
return items;
}
return todaycollection;
}
#endregion
private void startdate_OkButtonClicked(object source, SelectionChangedEventArgs args)
{
isvaluechange = true;
//(this.DataContext as ViewModel).StartDate = GetCollectionfromList(args.AddedItems[0] as IList);
startdatetxt.Text = GetStringfromCollection((this.DataContext as ViewModel).StartDate);
}
private void enddate_OkButtonClicked(object source, SelectionChangedEventArgs args)
{
isvaluechange = true;
//(this.DataContext as ViewModel).EndDate = GetCollectionfromList(args.AddedItems[0] as IList);
enddatetxt.Text = GetStringfromCollection((this.DataContext as ViewModel).EndDate);
}
private async void Button_Click_2(object sender, RoutedEventArgs e)
{
ContentDialog dialog = new ContentDialog();
dialog.Title = "Success";
dialog.Content = "Your vacation has been updated from "+startdatetxt.Text.ToString()+" to "+enddatetxt.Text.ToString();
dialog.PrimaryButtonText = "Ok";
await dialog.ShowAsync();
startdatetxt.Text = GetStringfromCollection(todaycollection);
enddatetxt.Text = GetStringfromCollection(todaycollection);
}
}
public class ViewModel : INotifyPropertyChanged
{
private ObservableCollection<object> _startdate;
public ObservableCollection<object> StartDate
{
get { return _startdate; }
set { _startdate = value; RaisePropertyChanged("StartDate"); }
}
private ObservableCollection<object> _enddate;
public ObservableCollection<object> EndDate
{
get { return _enddate; }
set { _enddate = value; RaisePropertyChanged("EndDate"); }
}
void RaisePropertyChanged(string name)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(name));
}
public event PropertyChangedEventHandler PropertyChanged;
public ViewModel()
{
ObservableCollection<object> todaycollection = new ObservableCollection<object>();
//Select today dates
todaycollection.Add(CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(DateTime.Now.Date.Month).Substring(0, 3));
if (DateTime.Now.Date.Day < 10)
todaycollection.Add("0" + DateTime.Now.Date.Day);
else
todaycollection.Add(DateTime.Now.Date.Day.ToString());
todaycollection.Add(DateTime.Now.Date.Year.ToString());
this.StartDate = todaycollection;
this.EndDate = todaycollection;
}
}
}