Пример #1
0
        private void OnSourceResolved(object oldValue, object newValue)
        {
            if (_isResolved)
            {
                return;
            }

            _bindingResolved(newValue);

            if (_autoDettach == false)
            {
                return;
            }

            _isResolved = true;

            ClearValue(SourceProperty);
            var dataItem = (DependencyObject)_dataItemRef.Target;

            if (dataItem == null)
            {
                return;
            }

            var resolvers = BindingResolverCollection.GetResolvers(dataItem);

            resolvers.Remove(this);
            if (resolvers.Count == 0)
            {
                dataItem.ClearValue(BindingResolverCollection.ResolversProperty);
            }
        }
Пример #2
0
        public BindingResolver(DependencyObject dataItem, Binding binding, Action <object> bindingResolved, bool autoDettach = true)
        {
            _dataItemRef     = new WeakReference(dataItem);
            _bindingResolved = bindingResolved;
            _autoDettach     = autoDettach;

            BindingResolverCollection.GetResolvers(dataItem).Add(this);
            BindingOperations.SetBinding(this, SourceProperty, binding);
        }