Exemplo n.º 1
0
        private static void OnValueChanged(DependencyObject dp, DependencyPropertyChangedEventArgs args)
        {
            //如果值没有发生变化,退出
            if ((args.NewValue != null && args.NewValue.Equals(args.OldValue)) || (args.NewValue == null && args.OldValue == null))
            {
                return;
            }
            PropertySetter ps = (PropertySetter)dp;

            //给属性赋值
            if (ps != null && ps.Object != null)
            {
                PropertyInfo pi = ps.Object.GetType().GetProperty(ps.PropertyName);
                //没有属性,或者是动态属性,调用动态属性的做法,否则,调用CLR属性的做法
                if (pi == null || pi is CustomPropertyInfoHelper)
                {
                    ps.Object.SetPropertyValue(ps.PropertyName, ps.Value, false);
                }
                else
                {
                    pi.SetValue(ps.Object, ps.Value, null);
                }
            }
        }