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.
17 using System.Threading;
19 using Tizen.NUI.BaseComponents;
20 using Tizen.NUI.Components;
22 namespace NUITizenGallery
24 public partial class LayoutAddRemoveTest2Page : ContentPage
27 public LayoutAddRemoveTest2Page()
29 InitializeComponent();
30 addButton.Clicked += OnAddButtonClicked;
31 addTaskButton.Clicked += OnAddTaskButtonClicked;
32 removeButton.Clicked += OnRemoveButtonClicked;
35 private void OnAddButtonClicked(object sender, ClickedEventArgs e)
39 WidthSpecification = 240,
40 HeightSpecification = 240,
41 BackgroundColor = new Color(red / 255f, 50f / 255f, 50 / 255f, 255f),
44 red = red > 255f ? 1f : red + 50f;
47 private void OnAddTaskButtonClicked(object sender, ClickedEventArgs e)
49 SynchronizationContext.Current.Post(AddButton, null);
52 private void OnRemoveButtonClicked(object sender, ClickedEventArgs e)
54 if (linear.ChildCount > 0)
56 linear.Remove(linear.Children[0]);
60 private void AddButton(object state)
62 linear.Add(new Button()
65 HeightSpecification = LayoutParamPolicies.MatchParent,
69 protected override void Dispose(DisposeTypes type)
76 if (type == DisposeTypes.Explicit)
78 addButton.Clicked -= OnAddButtonClicked;
79 addTaskButton.Clicked -= OnAddTaskButtonClicked;
80 removeButton.Clicked -= OnRemoveButtonClicked;
81 RemoveAllChildren(true);
87 private void RemoveAllChildren(bool dispose = false)
89 RecursiveRemoveChildren(this, dispose);
92 private void RecursiveRemoveChildren(View parent, bool dispose)
99 int maxChild = (int)parent.ChildCount;
100 for (int i = maxChild - 1; i >= 0; --i)
102 View child = parent.GetChildAt((uint)i);
107 RecursiveRemoveChildren(child, dispose);
108 parent.Remove(child);