private static object ConvertToPropertyType(object value, DependencyProperty dp, BindingExression be, IDataContextProvider source)
        {
            if (be.Log)
            {
                _logger.Debug("value: " + value);
            }

            if (be.Converter != null)
            {
                return(ApplyConverter(dp, be, value, source));
            }
            if (value == null || (value as string) == string.Empty || value == DependencyProperty.UnsetValue)
            {
                return(dp.GetDefaultValue());
            }

            var converter = TypeDescriptor.GetConverter(value.GetType());

            if (dp.PropertyType is IEnumerable <object> && value is MultiArticleField)
            {
                return(((MultiArticleField)value).Items.Values);
            }

            if (dp.PropertyType.IsInstanceOfType(value))
            {
                return(value);
            }

            if (dp.PropertyType == typeof(object))
            {
                return(value);
            }

            return(converter.ConvertTo(value, dp.PropertyType));
        }
Ejemplo n.º 2
0
        object ConvertToType(DependencyProperty dp, object value)
        {
            try {
                if (!PropertyPathWalker.IsPathBroken && Binding.Converter != null)
                {
                    value = Binding.Converter.Convert(
                        value,
                        Property.PropertyType,
                        Binding.ConverterParameter,
                        GetConverterCulture()
                        );
                }

                if (value == DependencyProperty.UnsetValue || PropertyPathWalker.IsPathBroken)
                {
                    value = Binding.FallbackValue ?? dp.GetDefaultValue(Target);
                }
                else if (value == null)
                {
                    value = Binding.TargetNullValue;
                    if (value == null && IsBoundToAnyDataContext && string.IsNullOrEmpty(Binding.Path.Path))
                    {
                        value = dp.GetDefaultValue(Target);
                    }
                }
                else
                {
                    string format = Binding.StringFormat;
                    if (!string.IsNullOrEmpty(format))
                    {
                        if (!format.Contains("{0"))
                        {
                            format = "{0:" + format + "}";
                        }
                        value = string.Format(GetConverterCulture(), format, value);
                    }
                }

                if (value != null)
                {
                    value = ConvertFromSourceToTarget(value);
                }
            } catch (Exception ex) {
                return(MoonlightTypeConverter.ConvertObject(dp, Binding.FallbackValue, Target.GetType(), true));
            }
            return(value);
        }
Ejemplo n.º 3
0
        internal override object GetValue(DependencyProperty dp)
        {
            if (cached)
            {
                return(cachedValue);
            }

            cached = true;
            if (PropertyPathWalker.IsPathBroken)
            {
                cachedValue = null;
            }
            else
            {
                cachedValue = PropertyPathWalker.Value;
            }
            try {
                cachedValue = ConvertToType(dp, cachedValue);
            } catch {
                cachedValue = dp.GetDefaultValue(Target);
            }

            return(cachedValue);
        }
Ejemplo n.º 4
0
        //  Helper method to update this panel's state related to children rendering order handling
        private void RecomputeZState()
        {
            int  count              = (_uiElementCollection != null) ? _uiElementCollection.Count : 0;
            bool isDiverse          = false;
            bool lutRequired        = false;
            int  zIndexDefaultValue = (int)ZIndexProperty.GetDefaultValue(DependencyObjectType);
            int  consonant          = zIndexDefaultValue;

            System.Collections.Generic.List <Int64> stableKeyValues = null;

            if (count > 0)
            {
                if (_uiElementCollection[0] != null)
                {
                    consonant = (int)_uiElementCollection[0].GetValue(ZIndexProperty);
                }

                if (count > 1)
                {
                    stableKeyValues = new System.Collections.Generic.List <Int64>(count);
                    stableKeyValues.Add((Int64)consonant << 32);

                    int prevZ = consonant;

                    int i = 1;
                    do
                    {
                        int z = _uiElementCollection[i] != null
                            ? (int)_uiElementCollection[i].GetValue(ZIndexProperty)
                            : zIndexDefaultValue;

                        //  this way of calculating values of stableKeyValues required to
                        //  1)  workaround the fact that Array.Sort is not stable (does not preserve the original
                        //      order of elements if the keys are equal)
                        //  2)  avoid O(N^2) performance of Array.Sort, which is QuickSort, which is known to become O(N^2)
                        //      on sorting N eqial keys
                        stableKeyValues.Add(((Int64)z << 32) + i);
                        //  look-up-table is required iff z's are not monotonically increasing function of index.
                        //  in other words if stableKeyValues[i] >= stableKeyValues[i-1] then calculated look-up-table
                        //  is guaranteed to be degenerated...
                        lutRequired |= z < prevZ;
                        prevZ        = z;

                        isDiverse |= (z != consonant);
                    } while (++i < count);
                }
            }

            if (lutRequired)
            {
                stableKeyValues.Sort();

                if (_zLut == null || _zLut.Length != count)
                {
                    _zLut = new int[count];
                }

                for (int i = 0; i < count; ++i)
                {
                    _zLut[i] = (int)(stableKeyValues[i] & 0xffffffff);
                }
            }
            else
            {
                _zLut = null;
            }

            IsZStateDiverse = isDiverse;
            _zConsonant     = consonant;
            IsZStateDirty   = false;
        }
Ejemplo n.º 5
0
        private int[] _zLut; //  look up table for converting from logical to visual indices

        /// <summary>
        ///     Default DependencyObject constructor
        /// </summary>
        /// <remarks>
        ///     Automatic determination of current Dispatcher. Use alternative constructor
        ///     that accepts a Dispatcher for best performance.
        /// </remarks>
        protected Panel()
            : base()
        {
            _zConsonant = (int)ZIndexProperty.GetDefaultValue(DependencyObjectType);
        }