1 using System.Collections.Generic;
2 using Tizen.NUI.BaseComponents;
3 using Tizen.NUI.Components;
4 using Tizen.NUI.Binding;
6 namespace Tizen.NUI.Samples
8 public class CollectionViewGridSample : IExample
10 CollectionView colView;
13 ItemSelectionMode selMode;
15 public void Activate()
17 Window window = NUIApplication.GetDefaultWindow();
19 var myViewModelSource = new GalleryViewModel(itemCount);
20 selMode = ItemSelectionMode.MultipleSelections;
21 DefaultTitleItem myTitle = new DefaultTitleItem();
22 myTitle.Text = "Grid Sample Count["+itemCount+"] Selected["+selectedCount+"]";
23 //Set Width Specification as MatchParent to fit the Item width with parent View.
24 myTitle.WidthSpecification = LayoutParamPolicies.MatchParent;
26 colView = new CollectionView()
28 ItemsSource = myViewModelSource,
29 ItemsLayouter = new GridLayouter(),
30 ItemTemplate = new DataTemplate(() =>
32 DefaultGridItem item = new DefaultGridItem();
33 item.WidthSpecification = 180;
34 item.HeightSpecification = 240;
36 item.Caption.SetBinding(TextLabel.TextProperty, "ViewLabel");
37 item.Caption.HorizontalAlignment = HorizontalAlignment.Center;
39 item.Image.SetBinding(ImageView.ResourceUrlProperty, "ImageUrl");
40 item.Image.WidthSpecification = 170;
41 item.Image.HeightSpecification = 170;
42 //Decorate Badge checkbox.
43 //[NOTE] This is sample of CheckBox usage in CollectionView.
44 // Checkbox change their selection by IsSelectedProperty bindings with
45 // SelectionChanged event with MulitpleSelections ItemSelectionMode of CollectionView.
46 item.Badge = new CheckBox();
47 //FIXME : SetBinding in RadioButton crashed as Sensitive Property is disposed.
48 //item.Badge.SetBinding(CheckBox.IsSelectedProperty, "Selected");
49 item.Badge.WidthSpecification = 30;
50 item.Badge.HeightSpecification = 30;
55 ScrollingDirection = ScrollableBase.Direction.Vertical,
56 WidthSpecification = LayoutParamPolicies.MatchParent,
57 HeightSpecification = LayoutParamPolicies.MatchParent,
58 SelectionMode = selMode
60 colView.SelectionChanged += SelectionEvt;
65 public void SelectionEvt(object sender, SelectionChangedEventArgs ev)
67 List<object> oldSel = new List<object>(ev.PreviousSelection);
68 List<object> newSel = new List<object>(ev.CurrentSelection);
70 foreach (object item in oldSel)
72 if (item != null && item is Gallery)
74 Gallery galItem = (Gallery)item;
75 if (!(newSel.Contains(item)))
77 galItem.Selected = false;
78 Tizen.Log.Debug("Unselected: {0}", galItem.ViewLabel);
84 foreach (object item in newSel)
86 if (item != null && item is Gallery)
88 Gallery galItem = (Gallery)item;
89 if (!(oldSel.Contains(item)))
91 galItem.Selected = true;
92 Tizen.Log.Debug("Selected: {0}", galItem.ViewLabel);
98 if (colView.Header != null && colView.Header is DefaultTitleItem)
100 DefaultTitleItem title = (DefaultTitleItem)colView.Header;
101 title.Text = "Grid Sample Count["+itemCount+"] Selected["+selectedCount+"]";
105 public void Deactivate()