2 using System.ComponentModel;
3 using System.Collections.Generic;
4 using System.Collections.ObjectModel;
5 using Tizen.NUI.BaseComponents;
6 using Tizen.NUI.Components;
7 using Tizen.NUI.Binding;
9 namespace Tizen.NUI.Samples
11 public class CollectionViewLinearGroupSample : IExample
13 CollectionView colView;
15 ItemSelectionMode selMode;
16 ObservableCollection<Album> albumSource;
17 Album insertDeleteGroup = new Album(999, "Insert / Delete Groups", new DateTime(1999, 12, 31));
18 Gallery insertMenu = new Gallery(999, "Insert item to first of 3rd Group");
19 Gallery deleteMenu = new Gallery(999, "Delete first item in 3rd Group");
20 Album moveGroup = new Album(999, "move Groups", new DateTime(1999, 12, 31));
21 Gallery moveMenu = new Gallery(999, "Move last item to first in 3rd group");
23 public void Activate()
25 Window window = NUIApplication.GetDefaultWindow();
27 albumSource = new AlbumViewModel();
28 // Add test menu options.
29 moveGroup.Add(moveMenu);
30 albumSource.Insert(0, moveGroup);
31 insertDeleteGroup.Add(insertMenu);
32 insertDeleteGroup.Add(deleteMenu);
33 albumSource.Insert(0, insertDeleteGroup);
35 selMode = ItemSelectionMode.SingleSelection;
36 DefaultTitleItem myTitle = new DefaultTitleItem();
37 //To Bind the Count property changes, need to create custom property for count.
38 myTitle.Text = "Linear Sample Group["+ albumSource.Count+"]";
39 //Set Width Specification as MatchParent to fit the Item width with parent View.
40 myTitle.WidthSpecification = LayoutParamPolicies.MatchParent;
42 colView = new CollectionView()
44 ItemsSource = albumSource,
45 ItemsLayouter = new LinearLayouter(),
46 ItemTemplate = new DataTemplate(() =>
48 DefaultLinearItem item = new DefaultLinearItem();
49 //Set Width Specification as MatchParent to fit the Item width with parent View.
50 item.WidthSpecification = LayoutParamPolicies.MatchParent;
52 item.Label.SetBinding(TextLabel.TextProperty, "ViewLabel");
53 item.Label.HorizontalAlignment = HorizontalAlignment.Begin;
55 item.Icon.SetBinding(ImageView.ResourceUrlProperty, "ImageUrl");
56 item.Icon.WidthSpecification = 80;
57 item.Icon.HeightSpecification = 80;
58 //Decorate Extra RadioButton.
59 //[NOTE] This is sample of RadioButton usage in CollectionView.
60 // RadioButton change their selection by IsSelectedProperty bindings with
61 // SelectionChanged event with SingleSelection ItemSelectionMode of CollectionView.
62 // be aware of there are no RadioButtonGroup.
63 item.Extra = new RadioButton();
64 //FIXME : SetBinding in RadioButton crashed as Sensitive Property is disposed.
65 //item.Extra.SetBinding(RadioButton.IsSelectedProperty, "Selected");
66 item.Extra.WidthSpecification = 80;
67 item.Extra.HeightSpecification = 80;
71 GroupHeaderTemplate = new DataTemplate(() =>
73 DefaultTitleItem group = new DefaultTitleItem();
74 //Set Width Specification as MatchParent to fit the Item width with parent View.
75 group.WidthSpecification = LayoutParamPolicies.MatchParent;
77 group.Label.SetBinding(TextLabel.TextProperty, "Date");
78 group.Label.HorizontalAlignment = HorizontalAlignment.Begin;
84 ScrollingDirection = ScrollableBase.Direction.Vertical,
85 WidthSpecification = LayoutParamPolicies.MatchParent,
86 HeightSpecification = LayoutParamPolicies.MatchParent,
87 SelectionMode = selMode
89 colView.SelectionChanged += SelectionEvt;
95 public void SelectionEvt(object sender, SelectionChangedEventArgs ev)
97 //Tizen.Log.Debug("NUI", "LSH :: SelectionEvt called");
99 //SingleSelection Only have 1 or nil object in the list.
100 foreach (object item in ev.PreviousSelection)
102 if (item == null) break;
103 if (item is Gallery unselItem)
105 unselItem.Selected = false;
107 //Tizen.Log.Debug("NUI", "LSH :: Unselected: {0}", unselItem.ViewLabel);
109 else if (item is Album selAlbum)
111 selectedItem = selAlbum.Title;
112 selAlbum.Selected = false;
113 if (selAlbum == insertDeleteGroup)
115 albumSource.RemoveAt(2);
120 foreach (object item in ev.CurrentSelection)
122 if (item == null) break;
123 if (item is Gallery selItem)
125 selItem.Selected = true;
126 selectedItem = selItem.Name;
127 //Tizen.Log.Debug("NUI", "LSH :: Selected: {0}", selItem.ViewLabel);
129 // Check test menu options.
130 if (selItem == insertMenu)
132 // Insert new item to index 3.
133 Random rand = new Random();
134 int idx = rand.Next(1000);
135 albumSource[2].Insert(0, new Gallery(idx, "Inserted Item"));
137 else if (selItem == deleteMenu)
139 // Remove item in index 3.
140 albumSource[2].RemoveAt(0);
142 else if (selItem == moveMenu)
144 // Move last indexed item to index 3.
145 albumSource[2].Move(albumSource[2].Count - 1, 0);
148 else if (item is Album selAlbum)
150 selectedItem = selAlbum.Title;
151 selAlbum.Selected = true;
152 if (selAlbum == insertDeleteGroup)
154 Random rand = new Random();
155 int groupIdx = rand.Next(1000);
156 Album insertAlbum = new Album(groupIdx, "Inserted group", new DateTime(1999, 12, 31));
157 int idx = rand.Next(1000);
158 insertAlbum.Add(new Gallery(idx, "Inserted Item 1"));
159 idx = rand.Next(1000);
160 insertAlbum.Add(new Gallery(idx, "Inserted Item 2"));
161 idx = rand.Next(1000);
162 insertAlbum.Add(new Gallery(idx, "Inserted Item 3"));
163 albumSource.Insert(2, insertAlbum);
165 else if (selAlbum == moveGroup)
167 albumSource.Move(albumSource.Count - 1, 2);
172 if (colView.Header != null && colView.Header is DefaultTitleItem)
174 DefaultTitleItem title = (DefaultTitleItem)colView.Header;
175 title.Text = "Linear Sample Count[" + albumSource.Count + (selectedItem != null ? "] Selected [" + selectedItem + "]" : "]");
179 public void Deactivate()