コード例 #1
0
ファイル: ObjectBinder.cs プロジェクト: GoldMax/Pulsar.NET
 /// <summary>
 /// Метод отмены регистрации биндинга
 /// </summary>
 /// <param name="binding"></param>
 public void UnregBinding(ObjectBinding binding)
 {
  lock(_list)
  {
   List<WeakReference> toDel = new List<WeakReference>(0);
   foreach(WeakReference wr in _list)
    if(wr.IsAlive == false || wr.Target == binding)
     toDel.Add(wr);
   if(toDel.Count > 0)
    foreach(WeakReference wr in toDel)
     _list.Remove(wr);
   if(binding.OnSourceValueChanged != null)
    binding.OnSourceValueChanged(null, false);
  }
 }
コード例 #2
0
ファイル: ObjectBinder.cs プロジェクト: GoldMax/Pulsar.NET
 //-------------------------------------------------------------------------------------
 #region << Methods >>
 /// <summary>
 /// Метод регистрации биндинга
 /// </summary>
 /// <param name="binding"></param>
 public void RegBinding(ObjectBinding binding)
 {
  lock(_list)
  {
   bool has = false;
   List<WeakReference> toDel = new List<WeakReference>(0);
   foreach(WeakReference wr in _list)
    if(wr.IsAlive == false)
     toDel.Add(wr);
    else if(wr.Target == binding)
    {
     if(((ObjectBinding)wr.Target).PropertyName == binding.PropertyName)
      break;
     wr.Target = binding;
     has = true;
     break;
    }
   if(toDel.Count > 0)  
    foreach(WeakReference wr in toDel)
     _list.Remove(wr);
   if(has == false)
    _list.Add(new WeakReference(binding));
   if(binding.OnSourceValueChanged != null && _type != null && _obj != null)
   {
    PropertyDescriptor pd = this[binding.PropertyName];
    if(pd == null)
     binding.OnSourceValueChanged(null, true);
    else
     binding.OnSourceValueChanged(pd.GetValue(_obj), false);
   }
  }
 }