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 CollectionViewGridGroupSample : IExample
13 CollectionView colView;
15 ItemSelectionMode selMode;
16 ObservableCollection<Album> groupSource;
18 public void Activate()
20 Window window = NUIApplication.GetDefaultWindow();
22 groupSource = new AlbumViewModel();
23 selMode = ItemSelectionMode.MultipleSelections;
24 DefaultTitleItem myTitle = new DefaultTitleItem();
25 myTitle.Text = "Grid Sample Count["+ groupSource.Count+"] Selected["+selectedCount+"]";
26 //Set Width Specification as MatchParent to fit the Item width with parent View.
27 myTitle.WidthSpecification = LayoutParamPolicies.MatchParent;
29 colView = new CollectionView()
31 ItemsSource = groupSource,
32 ItemsLayouter = new GridLayouter(),
33 ItemTemplate = new DataTemplate(() =>
35 DefaultGridItem item = new DefaultGridItem();
36 item.WidthSpecification = 180;
37 item.HeightSpecification = 240;
39 item.Caption.SetBinding(TextLabel.TextProperty, "ViewLabel");
40 item.Caption.HorizontalAlignment = HorizontalAlignment.Center;
42 item.Image.SetBinding(ImageView.ResourceUrlProperty, "ImageUrl");
43 item.Image.WidthSpecification = 170;
44 item.Image.HeightSpecification = 170;
45 //Decorate Badge checkbox.
46 //[NOTE] This is sample of CheckBox usage in CollectionView.
47 // Checkbox change their selection by IsSelectedProperty bindings with
48 // SelectionChanged event with MulitpleSelections ItemSelectionMode of CollectionView.
49 item.Badge = new CheckBox();
50 //FIXME : SetBinding in RadioButton crashed as Sensitive Property is disposed.
51 //item.Badge.SetBinding(CheckBox.IsSelectedProperty, "Selected");
52 item.Badge.WidthSpecification = 30;
53 item.Badge.HeightSpecification = 30;
57 GroupHeaderTemplate = new DataTemplate(() =>
59 DefaultTitleItem group = new DefaultTitleItem();
60 //Set Width Specification as MatchParent to fit the Item width with parent View.
61 group.WidthSpecification = LayoutParamPolicies.MatchParent;
63 group.Label.SetBinding(TextLabel.TextProperty, "Date");
64 group.Label.HorizontalAlignment = HorizontalAlignment.Begin;
70 ScrollingDirection = ScrollableBase.Direction.Vertical,
71 WidthSpecification = LayoutParamPolicies.MatchParent,
72 HeightSpecification = LayoutParamPolicies.MatchParent,
73 SelectionMode = selMode
75 colView.SelectionChanged += SelectionEvt;
80 public void SelectionEvt(object sender, SelectionChangedEventArgs ev)
82 List<object> oldSel = new List<object>(ev.PreviousSelection);
83 List<object> newSel = new List<object>(ev.CurrentSelection);
85 foreach (object item in oldSel)
87 if (item != null && item is Gallery)
89 Gallery galItem = (Gallery)item;
90 if (!(newSel.Contains(item)))
92 galItem.Selected = false;
93 Tizen.Log.Debug("Unselected: {0}", galItem.ViewLabel);
99 foreach (object item in newSel)
101 if (item != null && item is Gallery)
103 Gallery galItem = (Gallery)item;
104 if (!(oldSel.Contains(item)))
106 galItem.Selected = true;
107 Tizen.Log.Debug("Selected: {0}", galItem.ViewLabel);
113 if (colView.Header != null && colView.Header is DefaultTitleItem)
115 DefaultTitleItem title = (DefaultTitleItem)colView.Header;
116 title.Text = "Grid Sample Count["+ groupSource.Count + "] Selected["+selectedCount+"]";
120 public void Deactivate()