internal void OnPreSet(object sender, DependencyPropertyPreSetEventArgs e) { if (this.PreSet != null) { this.PreSet(sender, e); } }
/// <summary> /// ignoreExpression为true表示如果value是个表达式,那么不再执行表达式的SetValue,而是直接将值存到对象内部 /// </summary> /// <param name="dp"></param> /// <param name="value"></param> /// <param name="ignoreExpression">为true表示如果value是个表达式,那么不再执行表达式的SetValue,而是直接将值存到对象内部</param> internal void SetValue(DependencyProperty dp, object value, bool ignoreExpression) { var exp = value as Expression; if (exp != null) { this.ClearExpression(dp);//先移除之前的表达式 this.SetExpression(dp, exp); return; } var ctx = GetContext(dp.Id); if (!ctx.InCallBack) { //先进行对象内部回调方法 if (dp.PreSetValueCallback != null) { ctx.InCallBack = true; var result = dp.PreSetValueCallback(this, ref value); ctx.InCallBack = false; if (!result) { return; //false表示不再赋值 } } if (dp.IsRegisteredPreSet || this.PropertyPreSet != null) { var e = new DependencyPropertyPreSetEventArgs(dp, value); //再执行属性公共挂载的事件 if (dp.IsRegisteredPreSet) { ctx.InCallBack = true; dp.OnPreSet(this, e); ctx.InCallBack = false; if (!e.Allow) { return; //不再赋值 } value = e.Value; } //最后执行对象级别挂载的事件 if (this.PropertyPreSet != null) { ctx.InCallBack = true; this.PropertyPreSet(this, e); ctx.InCallBack = false; if (!e.Allow) { return; //不再赋值 } value = e.Value; } } } var oldValue = LoadPropertyValue(dp, ignoreExpression); if (!object.Equals(oldValue, value)) { SavePropertyValue(dp, value, ignoreExpression); OnPropertyChanged(dp, value, oldValue); } }
internal void OnPreSet(object sender, DependencyPropertyPreSetEventArgs e) { this.DefaultMetadata.OnPreSet(sender, e); }