Beispiel #1
0
        //监听依赖属性变化,调用属性变化方法
        public static void Watch(this DependencyObject source, string dependencyPropertyName, PropertyChangedCallback callback)
        {
            if (dependencyPropertyName == null || source == null || callback == null)
            {
                throw new ArgumentNullException();
            }
            Binding binding = new Binding(dependencyPropertyName)
            {
                Source = source, Mode = BindingMode.OneWay
            };
            BindingSlave bs = new BindingSlave();

            _bindings.Add(bs);
            bs.PropertyChanged += (o, e) =>
            {
                callback(source, new DependencyPropertyChangedEventArgs());
            };
            BindingOperations.SetBinding(bs, BindingSlave.ValueProperty, binding);
        }
Beispiel #2
0
 /// <summary>
 /// Creates the bindings.
 /// </summary>
 /// <param name="bindings">The bindings.</param>
 public void CreateBindings(IList bindings)
 {
     if (bindings != null)
     {
         foreach (Binding binding in bindings)
         {
             var slave = new BindingSlave(this);
             Children.Add(slave);
             if (_nameScope != null && !string.IsNullOrEmpty(binding.ElementName))
             {
                 var element = _nameScope.FindName(binding.ElementName);
                 binding.ElementName = null;
                 binding.Source      = element;
             }
             binding.TargetNullValue = null;
             binding.FallbackValue   = null;
             slave.SetBinding(BindingSlave.ValueProperty, binding);
         }
     }
 }
Beispiel #3
0
 private void SlaveValueChanged( BindingSlave slave )
 {
     TryUpdateBinding ();
 }
Beispiel #4
0
 /// <summary>
 /// Creates the bindings.
 /// </summary>
 /// <param name="bindings">The bindings.</param>
 public void CreateBindings( IList bindings )
 {
     if ( bindings != null )
     {
         foreach ( Binding binding in bindings )
         {
             var slave = new BindingSlave ( this );
             Children.Add ( slave );
             if ( _nameScope != null && !string.IsNullOrEmpty ( binding.ElementName ) )
             {
                 var element = _nameScope.FindName ( binding.ElementName );
                 binding.ElementName = null;
                 binding.Source = element;
             }
             binding.TargetNullValue = null;
             binding.FallbackValue = null;
             slave.SetBinding ( BindingSlave.ValueProperty, binding );
         }
     }
 }
Beispiel #5
0
 private void SlaveValueChanged(BindingSlave slave)
 {
     TryUpdateBinding();
 }