Пример #1
0
 public override void ApplyBind()
 {
     if (Target is DependencyObject dpo)
     {
         dpo.DependencyPropertyChanged += Dpo_DependencyPropertyChanged;
         if (Model == BindingMode.TwoWay)
         {
             var dpotValue = TargetPath.GetValueFromSteptSub(Target, 1);//倒数第二层
             if (dpotValue == null)
             {
                 throw new ArgumentException("绑定目标属性为空");
             }
             if (dpotValue is DependencyObject dpotDpValue)
             {
                 bindDp = dpotDpValue;
                 bindDp.DependencyPropertyChanged += Sdpo_DependencyPropertyChanged;//双向绑定监视属性
             }
         }
     }
     else
     {
         throw new ArgumentException("Target必须要继承于DependencyObject");
     }
     base.ApplyBind();
 }
Пример #2
0
        public override void ApplyBind()
        {
            if (Source is DependencyObject dpo)
            {
                if (Model == BindingMode.TwoWay)
                {
                    if (Target is DependencyObject dpot)
                    {
                        var dpotValue = TargetPath.GetValueFromSteptSub(Target, 1);//倒数第二层
                        if (dpotValue == null)
                        {
                            throw new ArgumentException("绑定目标属性为空");
                        }
                        if (dpotValue is DependencyObject dpotDpValue)
                        {
                            bindDp = dpotDpValue;
                            bindDp.DependencyPropertyChanged += Dpot_PropertyChanged;//双向绑定监视属性
                        }
                        else
                        {
                            throw new ArgumentException("绑定目标属性不为依赖属性");
                        }
                    }
                    else
                    {
                        throw new ArgumentException($"双向绑定时,{nameof(Target)}必须是DependencyObject");
                    }
                }

                dpo.DependencyPropertyChanged += Dpo_PropertyChanged;
            }
            else
            {
                throw new ArgumentException($"DependencyBinding应用绑定出错,属性{nameof(Source)}不为DependencyObject");
            }
            base.ApplyBind();
        }