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