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 CollectionViewTest7 : ContentPage
30 void OnScrolling(object sender, ScrollEventArgs e)
32 ObservableCollection<TestItem> source = ColView.ItemsSource as ObservableCollection<TestItem>;
33 if (source == null) return;
34 //Reached Bound of Scroll
35 if (e.ScrollPosition.Y == (ColView.ContentContainer.SizeHeight - ColView.SizeHeight))
37 int count = source.Count;
38 var Rand = new Random();
39 for (int i = count; i < count + 20; i++)
41 source.Add(new TestItem(i,
43 new Color(((float)(Rand.Next(255))/255),
44 ((float)(Rand.Next(255))/255),
45 ((float)(Rand.Next(255))/255), 1)));
50 public CollectionViewTest7()
52 InitializeComponent();
53 BindingContext = new TestSourceModel(40);
55 ColView.ItemTemplate = new DataTemplate(() =>
57 var item = new RecyclerViewItem()
59 WidthSpecification = LayoutParamPolicies.MatchParent,
60 HeightSpecification = 100,
62 item.SetBinding(View.BackgroundColorProperty, "BgColor");
63 var label = new TextLabel()
65 ParentOrigin = Tizen.NUI.ParentOrigin.Center,
66 PivotPoint = Tizen.NUI.PivotPoint.Center,
67 PositionUsesPivotPoint = true,
70 label.SetBinding(TextLabel.TextProperty, "Index");
75 // Currently ScrollableBase only support Scrolling and ScrollOutOfBound event.
76 ColView.Scrolling += OnScrolling;
79 protected override void Dispose(DisposeTypes type)
86 if (type == DisposeTypes.Explicit)
88 RemoveAllChildren(true);
94 private void RemoveAllChildren(bool dispose = false)
96 RecursiveRemoveChildren(this, dispose);
99 private void RecursiveRemoveChildren(View parent, bool dispose)
106 int maxChild = (int)parent.ChildCount;
107 for (int i = maxChild - 1; i >= 0; --i)
109 View child = parent.GetChildAt((uint)i);
115 RecursiveRemoveChildren(child, dispose);
116 parent.Remove(child);