2 * Copyright(c) 2021 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 using System.Collections.ObjectModel;
19 using System.ComponentModel;
21 using Tizen.NUI.Binding;
22 using Tizen.NUI.BaseComponents;
23 using Tizen.NUI.Components;
24 using Tizen.NUI.Components.Extension;
26 namespace NUITizenGallery
28 public partial class CollectionViewTest5Page : ContentPage
31 ObservableCollection<TestItem> source;
32 void OnSelect10Clicked(object sender, ClickedEventArgs e)
34 ColView.SelectedItem = item10;
37 void OnSelectionChanged(object sender, SelectionChangedEventArgs e)
39 TestItem SelectedItem = null;
41 foreach(TestItem item in e.CurrentSelection)
43 Console.WriteLine("Selected Item {0}", item?.GetHashCode());
49 message = "Source is NULL";
53 int index = source.IndexOf(SelectedItem);
54 message = index + " was Selected";
57 var btn = new Button() { Text = "Ok", };
58 btn.Clicked += (object s, ClickedEventArgs args) =>
63 Console.WriteLine(message);
64 DialogPage.ShowAlertDialog("Selected", message, btn);
67 public CollectionViewTest5Page()
69 InitializeComponent();
70 var MyModel = new TestSourceModel();
71 item10 = MyModel.TestSource[10];
73 ColView.ItemsSource = source = MyModel.TestSource;
74 ColView.ItemTemplate = new DataTemplate(() =>
76 var item = new RecyclerViewItem()
78 HeightSpecification = LayoutParamPolicies.MatchParent,
79 WidthSpecification = 200,
81 item.SetBinding(View.BackgroundColorProperty, "BgColor");
82 var label = new TextLabel()
84 ParentOrigin = Tizen.NUI.ParentOrigin.Center,
85 PivotPoint = Tizen.NUI.PivotPoint.Center,
86 PositionUsesPivotPoint = true,
89 label.SetBinding(TextLabel.TextProperty, "Index");
96 protected override void Dispose(DisposeTypes type)
103 if (type == DisposeTypes.Explicit)
105 RemoveAllChildren(true);
111 private void RemoveAllChildren(bool dispose = false)
113 RecursiveRemoveChildren(this, dispose);
116 private void RecursiveRemoveChildren(View parent, bool dispose)
123 int maxChild = (int)parent.ChildCount;
124 for (int i = maxChild - 1; i >= 0; --i)
126 View child = parent.GetChildAt((uint)i);
132 RecursiveRemoveChildren(child, dispose);
133 parent.Remove(child);