1 using System.Collections.Generic;
2 using Tizen.NUI.BaseComponents;
3 using Tizen.NUI.Components;
4 using Tizen.NUI.Binding;
5 using System.ComponentModel;
8 namespace Tizen.NUI.Samples
10 public class CollectionViewLinearSample : IExample
12 CollectionView colView;
15 ItemSelectionMode selMode;
17 public void Activate()
19 Window window = NUIApplication.GetDefaultWindow();
21 var myViewModelSource = new GalleryViewModel(itemCount);
22 selMode = ItemSelectionMode.SingleSelection;
23 DefaultTitleItem myTitle = new DefaultTitleItem();
24 myTitle.Text = "Linear Sample Count["+itemCount+"]";
25 //Set Width Specification as MatchParent to fit the Item width with parent View.
26 myTitle.WidthSpecification = LayoutParamPolicies.MatchParent;
28 colView = new CollectionView()
30 ItemsSource = myViewModelSource,
31 ItemsLayouter = new LinearLayouter(),
32 ItemTemplate = new DataTemplate(() =>
34 var rand = new Random();
35 RecyclerViewItem item = new RecyclerViewItem();
36 item.WidthSpecification = LayoutParamPolicies.MatchParent;
37 item.HeightSpecification = 100;
38 item.BackgroundColor = new Color((float)rand.NextDouble(), (float)rand.NextDouble(), (float)rand.NextDouble(), 1);
40 DefaultLinearItem item = new DefaultLinearItem();
41 //Set Width Specification as MatchParent to fit the Item width with parent View.
42 item.WidthSpecification = LayoutParamPolicies.MatchParent;
44 item.Label.SetBinding(TextLabel.TextProperty, "ViewLabel");
45 item.Label.HorizontalAlignment = HorizontalAlignment.Begin;
47 item.Icon.SetBinding(ImageView.ResourceUrlProperty, "ImageUrl");
48 item.Icon.WidthSpecification = 80;
49 item.Icon.HeightSpecification = 80;
50 //Decorate Extra RadioButton.
51 //[NOTE] This is sample of RadioButton usage in CollectionView.
52 // RadioButton change their selection by IsSelectedProperty bindings with
53 // SelectionChanged event with SingleSelection ItemSelectionMode of CollectionView.
54 // be aware of there are no RadioButtonGroup.
55 item.Extra = new RadioButton();
56 //FIXME : SetBinding in RadioButton crashed as Sensitive Property is disposed.
57 //item.Extra.SetBinding(RadioButton.IsSelectedProperty, "Selected");
58 item.Extra.WidthSpecification = 80;
59 item.Extra.HeightSpecification = 80;
65 ScrollingDirection = ScrollableBase.Direction.Vertical,
66 WidthSpecification = LayoutParamPolicies.MatchParent,
67 HeightSpecification = LayoutParamPolicies.MatchParent,
68 SelectionMode = selMode
70 colView.SelectionChanged += SelectionEvt;
76 public void SelectionEvt(object sender, SelectionChangedEventArgs ev)
78 //Tizen.Log.Debug("NUI", "LSH :: SelectionEvt called");
80 //SingleSelection Only have 1 or nil object in the list.
81 foreach (object item in ev.PreviousSelection)
83 if (item == null) break;
84 Gallery unselItem = (Gallery)item;
86 unselItem.Selected = false;
88 //Tizen.Log.Debug("NUI", "LSH :: Unselected: {0}", unselItem.ViewLabel);
90 foreach (object item in ev.CurrentSelection)
92 if (item == null) break;
93 Gallery selItem = (Gallery)item;
94 selItem.Selected = true;
95 selectedItem = selItem.Name;
96 //Tizen.Log.Debug("NUI", "LSH :: Selected: {0}", selItem.ViewLabel);
98 if (colView.Header != null && colView.Header is DefaultTitleItem)
100 DefaultTitleItem title = (DefaultTitleItem)colView.Header;
101 title.Text = "Linear Sample Count[" + itemCount + (selectedItem != null ? "] Selected [" + selectedItem + "]" : "]");
104 public void Deactivate()