2 using System.Collections.Generic;
3 using System.Collections.ObjectModel;
4 using System.Threading.Tasks;
5 using Tizen.NUI.BaseComponents;
7 namespace Tizen.NUI.Binding
9 internal static class TemplateUtilities
11 public static async Task<Element> FindTemplatedParentAsync(Element element)
13 if (element.RealParent is Application)
16 element = await GetRealParentAsync(element);
17 while (!Application.IsApplicationOrNull(element))
19 var controlTemplated = element as IControlTemplated;
20 element = await GetRealParentAsync(element);
26 public static Task<Element> GetRealParentAsync(Element element)
28 Element parent = element.RealParent;
29 if (parent is Application)
30 return Task.FromResult<Element>(null);
33 return Task.FromResult(parent);
35 var tcs = new TaskCompletionSource<Element>();
36 EventHandler handler = null;
37 handler = (sender, args) =>
39 tcs.TrySetResult(element.RealParent);
40 element.ParentSet -= handler;
42 element.ParentSet += handler;
47 public static void OnContentChanged(BindableObject bindable, object oldValue, object newValue)
51 public static void OnControlTemplateChanged(BindableObject bindable, object oldValue, object newValue)
53 var self = (IControlTemplated)bindable;
55 // First make sure any old ContentPresenters are no longer bound up. This MUST be
56 // done before we attempt to make the new template.
59 var queue = new Queue<Element>(16);
60 queue.Enqueue((Element)self);
62 while (queue.Count > 0)
64 ReadOnlyCollection<Element> children = queue.Dequeue().LogicalChildrenInternal;
65 for (var i = 0; i < children.Count; i++)
67 Element child = children[i];
68 var controlTemplated = child as IControlTemplated;
74 // Now remove all remnants of any other children just to be sure
75 while (self.InternalChildren.Count > 0)
77 self.InternalChildren.RemoveAt(self.InternalChildren.Count - 1);