2 using System.ComponentModel;
3 using System.Collections.Generic;
5 namespace Tizen.NUI.Binding
7 [EditorBrowsable(EditorBrowsableState.Never)]
8 public class DataTemplate : ElementTemplate
13 [EditorBrowsable(EditorBrowsableState.Never)]
19 /// Base constructor with specific Type.
21 /// <param name="Type">The Type of content.</param>
22 [EditorBrowsable(EditorBrowsableState.Never)]
23 public DataTemplate(Type type) : base(type)
28 /// Base constructor with loadTemplate function.
30 /// <param name="loadTemplate">The function of loading templated object.</param>
31 [EditorBrowsable(EditorBrowsableState.Never)]
32 public DataTemplate(Func<object> loadTemplate) : base(loadTemplate)
36 [EditorBrowsable(EditorBrowsableState.Never)]
37 public IDictionary<BindableProperty, BindingBase> Bindings { get; } = new Dictionary<BindableProperty, BindingBase>();
39 [EditorBrowsable(EditorBrowsableState.Never)]
40 public IDictionary<BindableProperty, object> Values { get; } = new Dictionary<BindableProperty, object>();
42 [EditorBrowsable(EditorBrowsableState.Never)]
43 public void SetBinding(BindableProperty property, BindingBase binding)
46 throw new ArgumentNullException(nameof(property));
48 throw new ArgumentNullException(nameof(binding));
50 Values.Remove(property);
51 Bindings[property] = binding;
54 [EditorBrowsable(EditorBrowsableState.Never)]
55 public void SetValue(BindableProperty property, object value)
58 throw new ArgumentNullException(nameof(property));
60 Bindings.Remove(property);
61 Values[property] = value;
64 internal override void SetupContent(object item)
70 void ApplyBindings(object item)
75 var bindable = item as BindableObject;
79 foreach (KeyValuePair<BindableProperty, BindingBase> kvp in Bindings)
81 if (Values.ContainsKey(kvp.Key))
82 throw new InvalidOperationException("Binding and Value found for " + kvp.Key.PropertyName);
84 bindable.SetBinding(kvp.Key, kvp.Value.Clone());
88 void ApplyValues(object item)
93 var bindable = item as BindableObject;
96 foreach (KeyValuePair<BindableProperty, object> kvp in Values)
97 bindable.SetValue(kvp.Key, kvp.Value);