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> groupSource;
18 public void Activate()
20 Window window = NUIApplication.GetDefaultWindow();
22 groupSource = new AlbumViewModel();
23 selMode = ItemSelectionMode.SingleSelection;
24 DefaultTitleItem myTitle = new DefaultTitleItem();
25 //To Bind the Count property changes, need to create custom property for count.
26 myTitle.Text = "Linear Sample Group["+ groupSource.Count+"]";
27 //Set Width Specification as MatchParent to fit the Item width with parent View.
28 myTitle.WidthSpecification = LayoutParamPolicies.MatchParent;
30 colView = new CollectionView()
32 ItemsSource = groupSource,
33 ItemsLayouter = new LinearLayouter(),
34 ItemTemplate = new DataTemplate(() =>
36 var rand = new Random();
37 RecyclerViewItem item = new RecyclerViewItem();
38 item.WidthSpecification = LayoutParamPolicies.MatchParent;
39 item.HeightSpecification = 100;
40 item.BackgroundColor = new Color((float)rand.NextDouble(), (float)rand.NextDouble(), (float)rand.NextDouble(), 1);
42 DefaultLinearItem item = new DefaultLinearItem();
43 //Set Width Specification as MatchParent to fit the Item width with parent View.
44 item.WidthSpecification = LayoutParamPolicies.MatchParent;
46 item.Label.SetBinding(TextLabel.TextProperty, "ViewLabel");
47 item.Label.HorizontalAlignment = HorizontalAlignment.Begin;
49 item.Icon.SetBinding(ImageView.ResourceUrlProperty, "ImageUrl");
50 item.Icon.WidthSpecification = 80;
51 item.Icon.HeightSpecification = 80;
52 //Decorate Extra RadioButton.
53 //[NOTE] This is sample of RadioButton usage in CollectionView.
54 // RadioButton change their selection by IsSelectedProperty bindings with
55 // SelectionChanged event with SingleSelection ItemSelectionMode of CollectionView.
56 // be aware of there are no RadioButtonGroup.
57 item.Extra = new RadioButton();
58 //FIXME : SetBinding in RadioButton crashed as Sensitive Property is disposed.
59 //item.Extra.SetBinding(RadioButton.IsSelectedProperty, "Selected");
60 item.Extra.WidthSpecification = 80;
61 item.Extra.HeightSpecification = 80;
65 GroupHeaderTemplate = new DataTemplate(() =>
67 var rand = new Random();
68 RecyclerViewItem item = new RecyclerViewItem();
69 item.WidthSpecification = LayoutParamPolicies.MatchParent;
70 item.HeightSpecification = 50;
71 item.BackgroundColor = new Color(0, 0, 0, 1);
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 Gallery unselItem = (Gallery)item;
105 unselItem.Selected = false;
107 //Tizen.Log.Debug("NUI", "LSH :: Unselected: {0}", unselItem.ViewLabel);
109 foreach (object item in ev.CurrentSelection)
111 if (item == null) break;
112 Gallery selItem = (Gallery)item;
113 selItem.Selected = true;
114 selectedItem = selItem.Name;
115 //Tizen.Log.Debug("NUI", "LSH :: Selected: {0}", selItem.ViewLabel);
117 if (colView.Header != null && colView.Header is DefaultTitleItem)
119 DefaultTitleItem title = (DefaultTitleItem)colView.Header;
120 title.Text = "Linear Sample Count[" + groupSource + (selectedItem != null ? "] Selected [" + selectedItem + "]" : "]");
123 public void Deactivate()