Exemple #1
0
        /// <summary>
        /// 合并数据
        /// </summary>
        /// <param name="source">数据源</param>
        /// <param name="destination">数据目标对象</param>
        /// <param name="overWrite">源数据是否覆盖目标数据</param>
        /// <returns>修改了目标对象的属性个数</returns>
        public static int MergeValues(
            XDependencyObject source,
            XDependencyObject destination,
            bool overWrite)
        {
            if (source == destination)
            {
                return(0);
            }
            if (source == null || destination == null)
            {
                return(0);
            }
            int result = 0;

            foreach (XDependencyProperty p in source.InnerValues.Keys)
            {
                if (destination.InnerValues.ContainsKey(p) == false)
                {
                    object v = source.GetValue(p);
                    if (v is ICloneable)
                    {
                        v = ((ICloneable)v).Clone();
                    }
                    destination.SetValue(p, v);
                    result++;
                }
                else
                {
                    if (overWrite)
                    {
                        bool back = destination._DisableDefaultValue;
                        destination._DisableDefaultValue = source._DisableDefaultValue;
                        destination.SetValue(p, source.GetValue(p));
                        destination._DisableDefaultValue = back;
                        result++;
                    }
                    //object v = source.GetValue( p );
                    //object v2 = destination.GetValue(p);
                    //if (v != v2)
                    //{
                    //    destination.SetValue(p, v);
                    //    result++;
                    //}
                }
            }
            return(result);
        }
        public override object GetValue(object component)
        {
            XDependencyObject obj = component as XDependencyObject;

            if (obj == null)
            {
                return(null);
            }
            else
            {
                return(obj.GetValue(this._Property));
            }
        }
        public override bool ShouldSerializeValue(object component)
        {
            XDependencyObject obj = component as XDependencyObject;

            if (obj != null)
            {
                object v = obj.GetValue(this._Property);
                if (this._Property.EqualsDefaultValue(v))
                {
                    return(false);
                }
            }
            return(true);
        }