/// <summary> /// Removes all data bindings for the given data binding /// target <paramref name="obj"/> from the index. /// </summary> /// <param name="obj"></param> public void RemoveFromIndex(IDataBindingSupport obj) { // Remove cached values lock (_globalValueCache) { Tuple <IDataBindingSupport, IBindableProperty>[] keysToRemove = _globalValueCache.Keys.Where(k => Equals(obj, k.Item1)).ToArray(); for (short i = -1; ++i != keysToRemove.Length;) { Tuple <IDataBindingSupport, IBindableProperty> key = keysToRemove[i]; _globalValueCache.Remove(key); } } lock (_globalDataBindingCache) { Tuple <IDataBindingSupport, IBindableProperty>[] keysToRemove = _globalDataBindingCache.Keys.Where(k => Equals(obj, k.Item1)).ToArray(); for (short i = -1; ++i != keysToRemove.Length;) { Tuple <IDataBindingSupport, IBindableProperty> key = keysToRemove[i]; DataBinding dataBinding = _globalDataBindingCache[key]; dataBinding.Dispose(); _globalDataBindingCache.Remove(key); } } }
/// <summary> /// Adds the given <paramref name="dataBinding"/> to the internal index for /// the given data binding target <paramref name="obj"/> /// with the given bound property <paramref name="property"/>. /// </summary> /// <param name="obj">Data binding target</param> /// <param name="property">Data binding property</param> /// <param name="dataBinding">Data binding to index</param> public void AddToIndex <TValue>(IDataBindingSupport obj, IBindableProperty <TValue> property, DataBinding dataBinding) { Tuple <IDataBindingSupport, IBindableProperty> key = Tuple.Create(obj, (IBindableProperty)property); lock (_globalDataBindingCache) { _globalDataBindingCache[key] = dataBinding; } }
/// <summary> /// Applies the given <paramref name="dataBinding"/> to the given <paramref name="uiElement"/> for the /// given <paramref name="property"/>. /// </summary> /// <param name="uiElement">UI Element that is used as target of the binding</param> /// <param name="property">Property that is being bound</param> /// <param name="dataBinding">Data binding</param> /// <exception cref="ArgumentNullException">If any parameter is NULL</exception> public static void Apply <TValue>(IDataBindingSupport uiElement, IBindableProperty <TValue> property, DataBinding dataBinding) { if (uiElement == null) { throw new ArgumentNullException(nameof(uiElement)); } if (property == null) { throw new ArgumentNullException(nameof(property)); } if (dataBinding == null) { throw new ArgumentNullException(nameof(dataBinding)); } dataBinding.Connect(uiElement, property); GlobalDataBindingIndex.Instance.AddToIndex(uiElement, property, dataBinding); }