2 * Copyright (c) 2018 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;}
39 /// The contents of ContentPage can be added into it.
41 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
42 [EditorBrowsable(EditorBrowsableState.Never)]
43 public static readonly BindableProperty ContentProperty = BindableProperty.Create(nameof(Content), typeof(View), typeof(ContentPage), null, propertyChanged: (bindable, oldValue, newValue) =>
45 var self = (ContentPage)bindable;
48 self.Root.Add((View)newValue);
50 var newElement = (Element)newValue;
51 if (newElement != null)
53 BindableObject.SetInheritedBindingContext(newElement, bindable.BindingContext);
58 /// The contents of ContentPage can be added into it.
60 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
61 [EditorBrowsable(EditorBrowsableState.Never)]
64 get { return (View)GetValue(ContentProperty); }
65 set { SetValue(ContentProperty, value); }
69 /// Method that is called when the binding content changes.
71 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
72 [EditorBrowsable(EditorBrowsableState.Never)]
73 protected override void OnBindingContextChanged()
75 base.OnBindingContextChanged();
77 View content = Content;
78 ControlTemplate controlTemplate = ControlTemplate;
79 if (content != null && controlTemplate != null)
81 SetInheritedBindingContext(content, BindingContext);
85 internal override void OnControlTemplateChanged(ControlTemplate oldValue, ControlTemplate newValue)
90 base.OnControlTemplateChanged(oldValue, newValue);
91 View content = Content;
92 ControlTemplate controlTemplate = ControlTemplate;
93 if (content != null && controlTemplate != null)
95 SetInheritedBindingContext(content, BindingContext);
102 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
103 [EditorBrowsable(EditorBrowsableState.Never)]
104 public ContentPage(Window win)
106 IsCreateByXaml = true;
109 Root.WidthResizePolicy = ResizePolicyType.FillToParent;
110 Root.HeightResizePolicy = ResizePolicyType.FillToParent;
116 /// The Resources property.
118 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
119 [EditorBrowsable(EditorBrowsableState.Never)]
120 public ResourceDictionary XamlResources
124 return Application.Current.XamlResources;
129 Application.Current.XamlResources = value;
134 /// To make the ContentPage instance be disposed.
136 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
137 [EditorBrowsable(EditorBrowsableState.Never)]
138 protected override void Dispose(DisposeTypes type)
145 if (type == DisposeTypes.Explicit)
148 //Release your own managed resources here.
149 //You should release all of your own disposable objects here.
152 //Release your own unmanaged resources here.
153 //You should not access any managed member here except static instance.
154 //because the execution order of Finalizes is non-deterministic.
157 Window.Instance.Remove(Root);
165 /// Check whether the content is empty.
167 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
168 [EditorBrowsable(EditorBrowsableState.Never)]
173 return ( Root.ChildCount == 0 ) ? true : false;
178 /// Clear all contents from this ContentPage.
180 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
181 [EditorBrowsable(EditorBrowsableState.Never)]
182 public void ClearContent()
186 //Remove it from the window
187 Window.Instance.Remove(Root);
193 Root.WidthResizePolicy = ResizePolicyType.FillToParent;
194 Root.HeightResizePolicy = ResizePolicyType.FillToParent;
195 Window.Instance.Add(Root);
201 private EventHandler _clearEventHandler;
206 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
207 [EditorBrowsable(EditorBrowsableState.Never)]
208 public event EventHandler ClearEvent
212 _clearEventHandler += value;
216 _clearEventHandler -= value;
220 private void ClearHandler()
222 if (_clearEventHandler != null)
224 _clearEventHandler(this, null);
229 /// Users can set focus logic codes here.
231 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
232 [EditorBrowsable(EditorBrowsableState.Never)]
233 public virtual void SetFocus() { }
235 private Dictionary<string, Transition> transDictionary = new Dictionary<string, Transition>();
237 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
238 [EditorBrowsable(EditorBrowsableState.Never)]
239 public Transition GetTransition(string transitionName)
241 Transition trans = null;
242 transDictionary.TryGetValue(transitionName, out trans);
246 private void LoadTransitions()
248 foreach (string str in transitionNames)
250 string resourceName = str + ".xaml";
251 Transition trans = null;
253 string resource = Tizen.Applications.Application.Current.DirectoryInfo.Resource;
255 string likelyResourcePath = resource + "animation/" + resourceName;
257 if (File.Exists(likelyResourcePath))
259 trans = Extensions.LoadObject<Transition>(likelyResourcePath);
263 transDictionary.Add(trans.Name, trans);
268 private string[] transitionNames;
270 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
271 [EditorBrowsable(EditorBrowsableState.Never)]
272 public string[] TransitionNames
276 return transitionNames;
280 transitionNames = value;