2 * Copyright (c) 2017 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.
18 using System.ComponentModel;
19 using Tizen.NUI.Binding;
20 using Tizen.NUI.BaseComponents;
22 using System.Collections.Generic;
28 /// The ContentPage class.
30 [ContentProperty("Content")]
31 [EditorBrowsable(EditorBrowsableState.Never)]
32 public class ContentPage : TemplatedPage
34 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
35 [EditorBrowsable(EditorBrowsableState.Never)]
36 public View Root {get; internal set;}
37 private Window Window;
39 internal static readonly BindableProperty ContentProperty = BindableProperty.Create(nameof(Content), typeof(View), typeof(ContentPage), null, propertyChanged: (bindable, oldValue, newValue) =>
41 // var self = (IControlTemplated)bindable;
42 // var newElement = (Element)newValue;
43 // if (self.ControlTemplate == null)
45 // while (self.InternalChildren.Count > 0)
47 // self.InternalChildren.RemoveAt(self.InternalChildren.Count - 1);
50 // if (newValue != null)
51 // self.InternalChildren.Add(newElement);
55 // if (newElement != null)
57 // BindableObject.SetInheritedBindingContext(newElement, bindable.BindingContext);
60 var self = (ContentPage)bindable;
63 self.Root.Add((View)newValue);
68 /// The contents of ContentPage can be added into it.
70 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
71 [EditorBrowsable(EditorBrowsableState.Never)]
74 get { return (View)GetValue(ContentProperty); }
75 set { SetValue(ContentProperty, value); }
79 /// Method that is called when the binding content changes.
81 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
82 [EditorBrowsable(EditorBrowsableState.Never)]
83 protected override void OnBindingContextChanged()
85 base.OnBindingContextChanged();
87 View content = Content;
88 ControlTemplate controlTemplate = ControlTemplate;
89 if (content != null && controlTemplate != null)
91 SetInheritedBindingContext(content, BindingContext);
95 internal override void OnControlTemplateChanged(ControlTemplate oldValue, ControlTemplate newValue)
100 base.OnControlTemplateChanged(oldValue, newValue);
101 View content = Content;
102 ControlTemplate controlTemplate = ControlTemplate;
103 if (content != null && controlTemplate != null)
105 SetInheritedBindingContext(content, BindingContext);
112 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
113 [EditorBrowsable(EditorBrowsableState.Never)]
114 public ContentPage(Window win)
116 IsCreateByXaml = true;
119 Root.WidthResizePolicy = ResizePolicyType.FillToParent;
120 Root.HeightResizePolicy = ResizePolicyType.FillToParent;
126 /// The Resources property.
128 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
129 [EditorBrowsable(EditorBrowsableState.Never)]
130 public ResourceDictionary XamlResources
134 return Application.Current.XamlResources;
139 Application.Current.XamlResources = value;
144 /// To make the ContentPage instance be disposed.
146 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
147 [EditorBrowsable(EditorBrowsableState.Never)]
148 protected override void Dispose(DisposeTypes type)
155 if (type == DisposeTypes.Explicit)
158 //Release your own managed resources here.
159 //You should release all of your own disposable objects here.
162 //Release your own unmanaged resources here.
163 //You should not access any managed member here except static instance.
164 //because the execution order of Finalizes is non-deterministic.
165 Window.Instance.Remove(Root);
173 /// Check whether the content is empty.
175 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
176 [EditorBrowsable(EditorBrowsableState.Never)]
181 return ( Root.ChildCount == 0 ) ? true : false;
186 /// Clear all contents from this ContentPage.
188 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
189 [EditorBrowsable(EditorBrowsableState.Never)]
190 public void ClearContent()
194 //Remove it from the window
195 Window.Instance.Remove(Root);
201 Root.WidthResizePolicy = ResizePolicyType.FillToParent;
202 Root.HeightResizePolicy = ResizePolicyType.FillToParent;
203 Window.Instance.Add(Root);
209 private EventHandler _clearEventHandler;
214 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
215 [EditorBrowsable(EditorBrowsableState.Never)]
216 public event EventHandler ClearEvent
220 _clearEventHandler += value;
224 _clearEventHandler -= value;
228 private void ClearHandler()
230 if (_clearEventHandler != null)
232 _clearEventHandler(this, null);
237 /// Users can set focus logic codes here.
239 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
240 [EditorBrowsable(EditorBrowsableState.Never)]
241 public virtual void SetFocus() { }
243 private Dictionary<string, Transition> transDictionary = new Dictionary<string, Transition>();
245 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
246 [EditorBrowsable(EditorBrowsableState.Never)]
247 public Animation CreateAnimation(string animationType)
249 Animation ani = null;
250 Transition trans = null;
251 transDictionary.TryGetValue(animationType, out trans);
253 ani = trans?.CreateAnimation();
257 private void CreateAnimationFactory()
259 foreach (string str in transitionType)
261 string resourceName = str + ".xaml";
262 Transition trans = null;
264 string resource = Tizen.Applications.Application.Current.DirectoryInfo.Resource;
266 string likelyResourcePath = resource + "animation/" + resourceName;
268 if (File.Exists(likelyResourcePath))
270 trans = Extensions.LoadTransition(likelyResourcePath);
273 transDictionary.Add(trans.Name, trans);
277 private string[] transitionType;
279 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
280 [EditorBrowsable(EditorBrowsableState.Never)]
281 public string[] TransitionType
285 return transitionType;
289 transitionType = value;
290 CreateAnimationFactory();