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