-
Notifications
You must be signed in to change notification settings - Fork 0
/
CollectionViewChallengePage.xaml.cs
234 lines (213 loc) · 8.22 KB
/
CollectionViewChallengePage.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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace CollectionViewChallenge.Views
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class CollectionViewChallengePage : ContentPage, INotifyPropertyChanged
{
List<string> oCollectionViewPicker = new List<string> { "Empty List", "Filled List" };
List<string> oCollectionViewEnabled = new List<string> { "Enable", "Disable" };
List<string> oCollectionViewLayout = new List<string> { "Horizontal", "Vertical" };
Dictionary<string, string> oCollectionViewDic;
private ItemsLayoutOrientation _myProperty;
public CollectionViewChallengePage()
{
try
{
InitializeComponent();
CVPickerEnabled.ItemsSource = oCollectionViewEnabled;
CVPickerLayout.ItemsSource = oCollectionViewLayout;
CVPicker.ItemsSource = oCollectionViewPicker;
AddItemsToList();
FillCollectionView();
AddItemsToScrollToPicker();
}
catch(Exception oExp)
{
}
}
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged([CallerMemberName] string name = "")
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}
public ItemsLayoutOrientation GILOrientation
{
get
{
return _myProperty;
}
set
{
if (_myProperty != value)
{
_myProperty = value;
OnPropertyChanged();
}
}
}
private void AddItemsToScrollToPicker()
{
try
{
List<string> oItems = new List<string>();
oItems.Add("First Element");
oItems.Add("Second Element");
oItems.Add("Third Element");
oItems.Add("Fourth Element");
oItems.Add("Fifth Element");
oItems.Add("Sixth Element");
oItems.Add("Seventh Element");
oItems.Add("Eigth Element");
oItems.Add("Nineth Element");
oItems.Add("Tenth Element");
ScrollToPicker.ItemsSource = oItems;
}
catch(Exception oExp)
{
}
}
private void AddItemsToList()
{
try
{
oCollectionViewDic = new Dictionary<string, string>();
oCollectionViewDic.Add("First Element", "tab_about.png");
oCollectionViewDic.Add("Second Element", "tab_about.png");
oCollectionViewDic.Add("Third Element", "tab_about.png");
oCollectionViewDic.Add("Fourth Element", "tab_about.png");
oCollectionViewDic.Add("Fifth Element", "tab_about.png");
oCollectionViewDic.Add("Sixth Element", "tab_about.png");
oCollectionViewDic.Add("Seventh Element", "tab_about.png");
oCollectionViewDic.Add("Eigth Element", "tab_about.png");
oCollectionViewDic.Add("Nineth Element", "tab_about.png");
oCollectionViewDic.Add("Tenth Element", "tab_about.png");
}
catch(Exception oExp)
{
}
}
private void FillCollectionView()
{
try
{
List<ListViewElements> oElements = new List<ListViewElements>();
foreach (var items in oCollectionViewDic)
{
ListViewElements NewSectionItem =
new ListViewElements()
{
LVName = items.Key,
LVImage = items.Value
};
oElements.Add(NewSectionItem);
}
CollectionListViewH.ItemsSource = oElements;
CollectionListViewV.ItemsSource = oElements;
}
catch(Exception oExp)
{
}
}
private void CVPicker_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
if (CollectionListViewH.ItemsSource != null && CVPicker.SelectedIndex == 0)
{
CollectionListViewH.ItemsSource = null;
CollectionListViewV.ItemsSource = null;
}
else if (CVPicker.SelectedIndex == 1)
{
AddItemsToList();
FillCollectionView();
}
}
catch(Exception oExp)
{
}
}
private void CVPickerLayout_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
if (CollectionListViewH.ItemsSource != null)
{
if (CVPickerLayout.SelectedIndex == 0)
{
CollectionListViewH.IsVisible = true;
CollectionListViewV.IsVisible = false;
ScrollToPicker.SelectedItem = null;
CVPickerEnabled.SelectedItem = null;
}
else if(CVPickerLayout.SelectedIndex == 1)
{
CollectionListViewH.IsVisible = false;
CollectionListViewV.IsVisible = true;
ScrollToPicker.SelectedItem = null;
CVPickerEnabled.SelectedItem = null;
}
}
}
catch(Exception oExp)
{
}
}
private void CVPickedEnabled_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
if (CollectionListViewH.ItemsSource != null)
{
if (CVPickerEnabled.SelectedIndex == 0)
{
CollectionListViewH.IsEnabled = true;
CollectionListViewV.IsEnabled = true;
}
else if (CVPickerEnabled.SelectedIndex == 1)
{
CollectionListViewH.IsEnabled = false;
CollectionListViewV.IsEnabled = false;
}
}
}
catch(Exception oExp)
{
}
}
private void CollectionListViewV_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
}
private void CollectionListViewH_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
}
private void ScrollToPicker_SelectedIndexChanged(object sender, EventArgs e)
{
if (CollectionListViewH.ItemsSource != null && CollectionListViewH.IsVisible)
{
List<ListViewElements> Items = (List<ListViewElements>)CollectionListViewH.ItemsSource;
ListViewElements Selecteditem = Items.Select(x => x).Where(y => y.LVName == ScrollToPicker.SelectedItem.ToString()).FirstOrDefault();
CollectionListViewH.ScrollTo(Selecteditem);
}
else if (CollectionListViewV.ItemsSource != null && CollectionListViewV.IsVisible)
{
List<ListViewElements> Items = (List<ListViewElements>)CollectionListViewV.ItemsSource;
ListViewElements Selecteditem = Items.Select(x => x).Where(y => y.LVName == ScrollToPicker.SelectedItem.ToString()).FirstOrDefault();
CollectionListViewV.ScrollTo(Selecteditem);
}
}
}
public class ListViewElements
{
public string LVName { get; set; }
public string LVImage { get; set; }
}
}