Exemplo n.º 1
0
        object IBindingValueProvider.GetValue(DependencyProperty prop, BindingExression be, IDataContextProvider source)
        {
            var value = GetValue(prop, be, source);

            value = ApplyConverter(prop, be, value, source);
            return(value);
        }
Exemplo n.º 2
0
        private static object GetMemberValue(DependencyProperty prop, BindingExression be, object context, Type type, string targetName)
        {
            var hashcode = ComputeHash(prop, be, type, targetName);
            var fpa      = Accessors.GetOrAdd(hashcode, p => new FastPropertyAccessor(type, targetName, be.BindingMode == BindingMode.Readonly));

            return(fpa.GetValue(context));
        }
        protected override object GetValueInternal(DependencyProperty prop, BindingExression be, object context)
        {
            if (!(context is Article))
            {
                throw new ArgumentException("context must be Article");
            }

            return(DPathProcessor.Process(be.Expression, (Article)context).Select(mop => mop.ModelObject).ToArray());
        }
Exemplo n.º 4
0
        protected virtual object GetValue(DependencyProperty prop, BindingExression be, IDataContextProvider source)
        {
            var dc = source?.GetDataContext(be);

            if (dc == null)
            {
                return(DependencyProperty.UnsetValue);
            }

            return(be.Expression == "$DataContext" ? dc : GetValueInternal(prop, be, dc));
        }
Exemplo n.º 5
0
        private BindingExression CreateExpression()
        {
            var be = new BindingExression(Path, Mode)
            {
                IsAbsolute           = IsAbsolute,
                Offset               = Offset,
                Converter            = Converter,
                Parameter            = Parameter,
                Log                  = Log,
                BindingValueProvider = BindingValueProvider
            };

            return(be);
        }
Exemplo n.º 6
0
        protected static object ApplyConverter(DependencyProperty dp, BindingExression be, object value, IDataContextProvider source)
        {
            if (be.Converter != null && value != DependencyProperty.UnsetValue)
            {
                var setter = be.Converter as IDataContextProviderSetter;
                setter?.ApplyProvider(source);

                value = be.Converter.Convert(value, dp.PropertyType, be.Parameter, CultureInfo.CurrentCulture);
                if (value == null)
                {
                    return(dp.GetDefaultValue());
                }
            }
            return(value);
        }
Exemplo n.º 7
0
        object IDataContextProvider.GetDataContext(BindingExression expr)
        {
            if (_overridenProvider != null)
            {
                return(_overridenProvider.GetDataContext(expr));
            }

            var list = GetDataContextList().Skip(expr.Offset);

            if (expr.IsAbsolute)
            {
                return(list.LastOrDefault());
            }
            else
            {
                return(list.FirstOrDefault());
            }
        }
Exemplo n.º 8
0
        internal void RegisterBinding(DependencyProperty dp, BindingExression bindingExpression)
        {
            // получим dependencyproperty
            if (dp == null)
            {
                throw new ArgumentNullException("dp");
            }

            if (dp.Log)
            {
                var logger = ObjectFactoryBase.Resolve <ILogger>();
                logger.Debug(string.Format("for {0} {1}.{2} {3} list: {4}", dp, dp.OwnerType, dp.PropertyType, bindingExpression.Expression, _bindings.GetHashCode()));
            }

            _bindings[dp] = bindingExpression;

            // удаляем текущее значение, если оно было
            _valueTable[dp] = new ValueEntry(DependencyProperty.UnsetValue);
        }
Exemplo n.º 9
0
 private static string ComputeHash(DependencyProperty prop, BindingExression be, Type type, string path)
 {
     return("_hash" + prop.uId + "_" + be.GetHashCode() + "!" + type.GetHashCode() + prop.OwnerType + "-" + be.BindingMode + "_" + path);
 }
Exemplo n.º 10
0
        protected object GetHierarchicalMemberInvocationValue(DependencyProperty prop, BindingExression be, object context, string targetName)
        {
            if (string.IsNullOrEmpty(targetName))
            {
                return(context);
            }

            var array = targetName.Split(new[] { '.' }, StringSplitOptions.RemoveEmptyEntries);
            var value = context;

            foreach (var memberAccess in array)
            {
                if (value != null)
                {
                    value = GetMemberValue(prop, be, value, value.GetType(), memberAccess);
                }
            }

            return(value);
        }
Exemplo n.º 11
0
 protected virtual object GetValueInternal(DependencyProperty prop, BindingExression be, object context)
 {
     return(GetHierarchicalMemberInvocationValue(prop, be, context, be.Expression));
 }