2 using System.Collections.Generic;
4 namespace Tizen.NUI.Binding
6 internal class DataTemplate : ElementTemplate
12 public DataTemplate(Type type) : base(type)
16 public DataTemplate(Func<object> loadTemplate) : base(loadTemplate)
20 public IDictionary<BindableProperty, BindingBase> Bindings { get; } = new Dictionary<BindableProperty, BindingBase>();
22 public IDictionary<BindableProperty, object> Values { get; } = new Dictionary<BindableProperty, object>();
24 public void SetBinding(BindableProperty property, BindingBase binding)
27 throw new ArgumentNullException(nameof(property));
29 throw new ArgumentNullException(nameof(binding));
31 Values.Remove(property);
32 Bindings[property] = binding;
35 public void SetValue(BindableProperty property, object value)
38 throw new ArgumentNullException(nameof(property));
40 Bindings.Remove(property);
41 Values[property] = value;
44 internal override void SetupContent(object item)
50 void ApplyBindings(object item)
55 var bindable = item as BindableObject;
59 foreach (KeyValuePair<BindableProperty, BindingBase> kvp in Bindings)
61 if (Values.ContainsKey(kvp.Key))
62 throw new InvalidOperationException("Binding and Value found for " + kvp.Key.PropertyName);
64 bindable.SetBinding(kvp.Key, kvp.Value.Clone());
68 void ApplyValues(object item)
73 var bindable = item as BindableObject;
76 foreach (KeyValuePair<BindableProperty, object> kvp in Values)
77 bindable.SetValue(kvp.Key, kvp.Value);