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.Generic;
19 using System.Collections.ObjectModel;
20 using System.ComponentModel;
22 using Tizen.NUI.Binding;
23 using Tizen.NUI.BaseComponents;
24 using Tizen.NUI.Components;
25 using Tizen.NUI.Components.Extension;
27 namespace NUITizenGallery
29 public partial class CollectionViewTest9 : ContentPage
31 void OnCheckClicked(object sender, ClickedEventArgs e)
33 CheckBox check = sender as CheckBox;
34 if (check == null) return;
35 if (check.BindingContext == null) return;
36 var item = check.BindingContext;
37 if (item is TestItem tItem)
39 tItem.IsSelected = check.IsSelected;
40 Console.WriteLine($"On Clicked {tItem.Index} : {tItem.IsSelected}");
45 void OnSelectionChanged(object sender, SelectionChangedEventArgs e)
47 List<object> cur = new List<object>(e.CurrentSelection);
49 foreach(TestItem item in e.PreviousSelection)
51 if (cur.Contains(item)) continue;
52 item.IsSelected = false;
53 Console.WriteLine($"On Selection {item.Index} : {item.IsSelected}");
55 foreach(TestItem item in cur)
57 item.IsSelected = true;
58 Console.WriteLine($"On Selection {item.Index} : {item.IsSelected}");
62 public CollectionViewTest9()
64 InitializeComponent();
65 BindingContext = new GroupTestSourceModel(5, 5);
67 ColView.ItemTemplate = new DataTemplate(() =>
69 var item = new DefaultLinearItem()
71 WidthSpecification = LayoutParamPolicies.MatchParent,
73 item.Label.SetBinding(TextLabel.TextProperty, "Name");
77 WidthSpecification = 60,
78 HeightSpecification = 60
80 icon.SetBinding(BackgroundColorProperty, "BgColor");
83 var check = new CheckBox()
85 WidthSpecification = 60,
86 HeightSpecification = 60,
88 check.SetBinding(Button.IsSelectedProperty, "IsSelected");
89 check.Clicked += OnCheckClicked;
94 ColView.GroupHeaderTemplate = new DataTemplate(() =>
96 var header = new DefaultTitleItem()
98 WidthSpecification = LayoutParamPolicies.MatchParent,
100 header.Label.SetBinding(TextLabel.TextProperty, "GroupName");
106 protected override void Dispose(DisposeTypes type)
113 if (type == DisposeTypes.Explicit)
115 RemoveAllChildren(true);
121 private void RemoveAllChildren(bool dispose = false)
123 RecursiveRemoveChildren(this, dispose);
126 private void RecursiveRemoveChildren(View parent, bool dispose)
133 int maxChild = (int)parent.ChildCount;
134 for (int i = maxChild - 1; i >= 0; --i)
136 View child = parent.GetChildAt((uint)i);
142 RecursiveRemoveChildren(child, dispose);
143 parent.Remove(child);