[NUI] sync with https://github.com/nui-dali/NUITizenGallery
[platform/core/csapi/tizenfx.git] / test / NUITizenGallery / Examples / GridTest4 / GridTest4.xaml.cs
1 /*
2  * Copyright(c) 2021 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17 using System;
18 using Tizen.NUI;
19 using Tizen.NUI.BaseComponents;
20 using Tizen.NUI.Components;
21
22 namespace NUITizenGallery
23 {
24     public partial class GridTest4Page : ContentPage
25     {
26         public GridTest4Page()
27         {
28             InitializeComponent();
29             btn2.BackgroundColor = Color.Gray;
30             btn3.BackgroundColor = Color.Yellow;
31             btn4.BackgroundColor = Color.Green;
32             btn4.TextColor = Color.Pink;
33             btn5.BackgroundColor = Color.Purple;
34         }
35         protected override void Dispose(DisposeTypes type)
36         {
37             if (Disposed)
38             {
39                 return;
40             }
41
42             if (type == DisposeTypes.Explicit)
43             {
44                 RemoveAllChildren(true);
45             }
46
47             base.Dispose(type);
48         }
49
50         private void RemoveAllChildren(bool dispose = false)
51         {
52             RecursiveRemoveChildren(this, dispose);
53         }
54
55         private void RecursiveRemoveChildren(View parent, bool dispose)
56         {
57             if (parent == null)
58             {
59                 return;
60             }
61
62             int maxChild = (int)parent.ChildCount;
63             for (int i = maxChild - 1; i >= 0; --i)
64             {
65                 View child = parent.GetChildAt((uint)i);
66                 if (child == null)
67                 {
68                     continue;
69                 }
70
71                 RecursiveRemoveChildren(child, dispose);
72                 parent.Remove(child);
73                 if (dispose)
74                 {
75                     child.Dispose();
76                 }
77             }
78         }
79     }
80 }
81