13e48c82fa3b6fe3ecf1ef50cea220310836d31c
[platform/core/csapi/tizenfx.git] / test / NUITizenGallery / Examples / EntryTest2 / EntryTest2Page.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 Tizen.NUI;
18 using Tizen.NUI.BaseComponents;
19
20 namespace NUITizenGallery
21 {
22     public partial class EntryTest2Page : View
23     {
24         public EntryTest2Page()
25         {
26             InitializeComponent();
27         }
28         protected override void Dispose(DisposeTypes type)
29         {
30             if (Disposed)
31             {
32                 return;
33             }
34
35             if (type == DisposeTypes.Explicit)
36             {
37                 RemoveAllChildren(true);
38             }
39
40             base.Dispose(type);
41         }
42
43         private void RemoveAllChildren(bool dispose = false)
44         {
45             RecursiveRemoveChildren(this, dispose);
46         }
47
48         private void RecursiveRemoveChildren(View parent, bool dispose)
49         {
50             if (parent == null)
51             {
52                 return;
53             }
54
55             int maxChild = (int)parent.ChildCount;
56             for (int i = maxChild - 1; i >= 0; --i)
57             {
58                 View child = parent.GetChildAt((uint)i);
59                 if (child == null)
60                 {
61                     continue;
62                 }
63
64                 RecursiveRemoveChildren(child, dispose);
65                 parent.Remove(child);
66                 if (dispose)
67                 {
68                     child.Dispose();
69                 }
70             }
71         }
72     }
73 }