1 using System.Collections.Generic;
2 using System.Collections.ObjectModel;
3 using Tizen.NUI.BaseComponents;
4 using Tizen.NUI.Components;
5 using Tizen.NUI.Binding;
6 using System.ComponentModel;
9 namespace Tizen.NUI.Samples
11 public class CollectionViewLinearSample : IExample
13 CollectionView colView;
16 ItemSelectionMode selMode;
17 ObservableCollection<Gallery> gallerySource;
18 Gallery insertMenu = new Gallery(999, "Insert item to 3rd");
19 Gallery deleteMenu = new Gallery(999, "Delete item at 3rd");
20 Gallery moveMenu = new Gallery(999, "Move last item to 3rd");
23 public void Activate()
25 Window window = NUIApplication.GetDefaultWindow();
27 var myViewModelSource = gallerySource = new GalleryViewModel(itemCount);
28 // Add test menu options.
29 gallerySource.Insert(0, moveMenu);
30 gallerySource.Insert(0, deleteMenu);
31 gallerySource.Insert(0, insertMenu);
33 selMode = ItemSelectionMode.SingleSelection;
34 DefaultTitleItem myTitle = new DefaultTitleItem();
35 myTitle.Text = "Linear Sample Count["+itemCount+"]";
36 //Set Width Specification as MatchParent to fit the Item width with parent View.
37 myTitle.WidthSpecification = LayoutParamPolicies.MatchParent;
39 colView = new CollectionView()
41 ItemsSource = myViewModelSource,
42 ItemsLayouter = new LinearLayouter(),
43 ItemTemplate = new DataTemplate(() =>
45 var rand = new Random();
46 DefaultLinearItem item = new DefaultLinearItem();
47 //Set Width Specification as MatchParent to fit the Item width with parent View.
48 item.WidthSpecification = LayoutParamPolicies.MatchParent;
51 item.Label.SetBinding(TextLabel.TextProperty, "ViewLabel");
52 item.Label.HorizontalAlignment = HorizontalAlignment.Begin;
55 if ((rand.Next() % 2) == 0)
57 item.SubLabel.SetBinding(TextLabel.TextProperty, "Name");
58 item.SubLabel.HorizontalAlignment = HorizontalAlignment.Begin;
62 item.Icon.SetBinding(ImageView.ResourceUrlProperty, "ImageUrl");
63 item.Icon.WidthSpecification = 48;
64 item.Icon.HeightSpecification = 48;
66 //Decorate Extra RadioButton.
67 //[NOTE] This is sample of RadioButton usage in CollectionView.
68 // RadioButton change their selection by IsSelectedProperty bindings with
69 // SelectionChanged event with SingleSelection ItemSelectionMode of CollectionView.
70 // be aware of there are no RadioButtonGroup.
71 item.Extra = new RadioButton();
72 //FIXME : SetBinding in RadioButton crashed as Sensitive Property is disposed.
73 //item.Extra.SetBinding(RadioButton.IsSelectedProperty, "Selected");
74 item.Extra.WidthSpecification = 48;
75 item.Extra.HeightSpecification = 48;
80 ScrollingDirection = ScrollableBase.Direction.Vertical,
81 WidthSpecification = LayoutParamPolicies.MatchParent,
82 HeightSpecification = LayoutParamPolicies.MatchParent,
83 SelectionMode = selMode
85 colView.SelectionChanged += SelectionEvt;
91 public void SelectionEvt(object sender, SelectionChangedEventArgs ev)
93 //Tizen.Log.Debug("NUI", "LSH :: SelectionEvt called");
95 //SingleSelection Only have 1 or nil object in the list.
96 foreach (object item in ev.PreviousSelection)
98 if (item == null) break;
99 Gallery unselItem = (Gallery)item;
101 unselItem.Selected = false;
103 //Tizen.Log.Debug("NUI", "LSH :: Unselected: {0}", unselItem.ViewLabel);
105 foreach (object item in ev.CurrentSelection)
107 if (item == null) break;
108 Gallery selItem = (Gallery)item;
109 //selItem.Selected = true;
110 selectedItem = selItem.Name;
112 // Check test menu options.
113 if (selItem == insertMenu)
115 // Insert new item to index 3.
116 Random rand = new Random();
117 int idx = rand.Next(1000);
118 gallerySource.Insert(3, new Gallery(idx, "Inserted Item"));
120 else if (selItem == deleteMenu)
122 // Remove item in index 3.
123 gallerySource.RemoveAt(3);
125 else if (selItem == moveMenu)
127 // Move last indexed item to index 3.
128 gallerySource.Move(gallerySource.Count - 1, 3);
130 //Tizen.Log.Debug("NUI", "LSH :: Selected: {0}", selItem.ViewLabel);
132 if (colView.Header != null && colView.Header is DefaultTitleItem)
134 DefaultTitleItem title = (DefaultTitleItem)colView.Header;
135 title.Text = "Linear Sample Count[" + gallerySource.Count + (selectedItem != null ? "] Selected [" + selectedItem + "]" : "]");
139 public void Deactivate()