/// <summary>
        /// Attaches this multi binding to change events of the specified (child) binding <paramref name="bme"/>.
        /// </summary>
        /// <param name="bme">(Child) binding to be attached to.</param>
        protected void AttachToSourceBinding(BindingExtension bme)
        {
            IDataDescriptor dd = bme.EvaluatedSourceValue;

            dd.Attach(OnSourceBindingChanged);
            _attachedDataDescriptors.Add(dd);
        }
        /// <summary>
        /// Initializes the <see cref="ItemsControl.ItemsSource"/> property with the <see cref="SubItemsProvider"/>.
        /// </summary>
        /// <returns><c>true</c>, if the <see cref="ItemsControl.ItemsSource"/> property was changed by this method, else <c>false</c>.</returns>
        protected virtual bool InitializeSubItemsSource()
        {
            SubItemsProvider sip            = SubItemsProvider;
            IEnumerable      oldItemsSource = ItemsSource;

            if (!_contextChangedAttached)
            {
                ContextChanged         += OnContextChanged;
                _contextChangedAttached = true;
            }
            if (_attachedContextSource != null)
            {
                _attachedContextSource.Detach(OnDataContextValueChanged);
            }
            _attachedContextSource = DataContext.EvaluatedSourceValue;
            _attachedContextSource.Attach(OnDataContextValueChanged);
            object context = Context;

            if (context == null)
            {
                return(false);
            }
            ItemsSource = sip == null ? null : sip.GetSubItems(context);
            if (oldItemsSource == ItemsSource)
            {
                return(false);
            }
            MPF.TryCleanupAndDispose(oldItemsSource);
            CheckExpandable();
            return(true);
        }
Пример #3
0
 protected void AttachToDataDescriptor(UIElement element)
 {
     if (_element == null)
     {
         return;
     }
     if (!String.IsNullOrEmpty(Property))
     {
         string property = Property;
         int    index    = property.IndexOf('.');
         if (index != -1)
         {
             string propertyProvider = property.Substring(0, index);
             string propertyName     = property.Substring(index + 1);
             DefaultAttachedPropertyDataDescriptor result;
             if (!DefaultAttachedPropertyDataDescriptor.CreateAttachedPropertyDataDescriptor(new MpfNamespaceHandler(),
                                                                                             element, propertyProvider, propertyName, out result))
             {
                 ServiceRegistration.Get <ILogger>().Warn(
                     string.Format("Attached property '{0}' cannot be set on element '{1}'", property, element));
                 return;
             }
             _dataDescriptor = result;
             _dataDescriptor.Attach(OnPropertyChanged);
         }
         else
         {
             if (ReflectionHelper.FindMemberDescriptor(_element, Property, out _dataDescriptor))
             {
                 _dataDescriptor.Attach(OnPropertyChanged);
             }
         }
     }
 }
 /// <summary>
 /// Attaches a change handler to the specified data descriptor
 /// <paramref name="source"/>, which will be used as binding source.
 /// </summary>
 protected void AttachToSource(IDataDescriptor source)
 {
     if (source != null && source.SupportsChangeNotification)
     {
         _attachedSource = source;
         _attachedSource.Attach(OnBindingSourceChange);
     }
 }
Пример #5
0
 protected void AttachToDataDescriptor()
 {
     if (_element == null)
     {
         return;
     }
     if (!String.IsNullOrEmpty(Property))
     {
         if (ReflectionHelper.FindMemberDescriptor(_element, Property, out _dataDescriptor))
         {
             _dataDescriptor.Attach(OnPropertyChanged);
         }
     }
 }
Пример #6
0
 /// <summary>
 /// Creates a new <see cref="BindingDependency"/> object.
 /// </summary>
 /// <param name="sourceDd">Souce data descriptor for the dependency.</param>
 /// <param name="targetDd">Target data descriptor for the dependency.</param>
 /// <param name="autoAttachToSource">If set to <c>true</c>, the new dependency object will be
 /// automatically attached to the <paramref name="sourceDd"/> data descriptor. This means it will
 /// capture changes from it and reflect them on the <paramref name="targetDd"/> data descriptor.</param>
 /// <param name="updateSourceTrigger">This parameter controls, which target object event makes this
 /// binding dependency copy the target value to the <paramref name="sourceDd"/> data descriptor.
 /// If set to <see cref="UpdateSourceTrigger.PropertyChanged"/>, the new binding dependency object
 /// will automatically attach to property changes of the <paramref name="targetDd"/> data descriptor and
 /// reflect the changed value to the <paramref name="sourceDd"/> data descriptor. If set to
 /// <see cref="UpdateSourceTrigger.LostFocus"/>, the new binding dependency will attach to the
 /// <see cref="UIElement.EventOccured"/> event of the <paramref name="parentUiElement"/> object.
 /// If set to <see cref="UpdateSourceTrigger.Explicit"/>, the new binding dependency won't attach to
 /// the target at all.</param>
 /// <param name="parentUiElement">The parent <see cref="UIElement"/> of the specified <paramref name="targetDd"/>
 /// data descriptor. This parameter is used to raise the source/target updated events if
 /// <paramref name="notifyOnSourceUpdated"/> or <paramref name="notifyOntargetUpdated"/> are set to <c>true</c>
 /// and attach to the lost focus event if <paramref name="updateSourceTrigger"/> is set to
 /// <see cref="UpdateSourceTrigger.LostFocus"/>.</param>
 /// <param name="customValueConverter">Set a custom value converter with this parameter. If this parameter
 /// is set to <c>null</c>, the default <see cref="TypeConverter"/> will be used.</param>
 /// <param name="customValueConverterParameter">Parameter to be used in the custom value converter, if one is
 /// set.</param>
 /// <param name="notifyOnSourceUpdated">If set to <c>true</c>, the new dependency object will raise a
 /// <see cref="BindingExtension.SourceUpdatedEvent"/></param> on the <paramref name="parentUiElement"/>
 /// when the <paramref name="sourceDd"/> is updated with a value from the <paramref name="targetDd"/>.
 /// <param name="notifyOntargetUpdated">If set to <c>true</c>, the new dependency object will raise a
 /// <see cref="BindingExtension.TargetUpdatedEvent"/></param> on the <paramref name="parentUiElement"/>
 /// when the <paramref name="targetDd"/> is updated with a value from the <paramref name="sourceDd"/>.
 public BindingDependency(IDataDescriptor sourceDd, IDataDescriptor targetDd, bool autoAttachToSource,
                          UpdateSourceTrigger updateSourceTrigger, UIElement parentUiElement,
                          IValueConverter customValueConverter, object customValueConverterParameter,
                          bool notifyOnSourceUpdated, bool notifyOntargetUpdated)
 {
     _sourceDd              = sourceDd;
     _targetDd              = targetDd;
     _targetObject          = _targetDd.TargetObject as DependencyObject;
     _sourceObject          = _sourceDd.TargetObject as DependencyObject;
     _valueConverter        = customValueConverter;
     _converterParameter    = customValueConverterParameter;
     _notifyOnSourceUpdated = notifyOnSourceUpdated;
     _notifyOnTargetUpdated = notifyOntargetUpdated;
     _parentUiElement       = parentUiElement;
     if (autoAttachToSource && sourceDd.SupportsChangeNotification)
     {
         sourceDd.Attach(OnSourceChanged);
         _attachedToSource = true;
     }
     if (targetDd.SupportsChangeNotification)
     {
         if (updateSourceTrigger == UpdateSourceTrigger.PropertyChanged)
         {
             targetDd.Attach(OnTargetChanged);
             _attachedToTarget = true;
         }
         else if (updateSourceTrigger == UpdateSourceTrigger.LostFocus)
         {
             if (parentUiElement != null)
             {
                 parentUiElement.EventOccured += OnTargetElementEventOccured;
             }
             _attachedToLostFocus = true;
         }
     }
     // Initially update endpoints
     if (autoAttachToSource)
     {
         UpdateTarget();
     }
     if (updateSourceTrigger != UpdateSourceTrigger.Explicit &&
         !autoAttachToSource) // If we are attached to both, only update one direction
     {
         UpdateSource();
     }
 }
Пример #7
0
 void Attach()
 {
     if (_element == null)
     {
         return;
     }
     if (!string.IsNullOrEmpty(Property))
     {
         if (ReflectionHelper.FindMemberDescriptor(_element, Property, out _dataDescriptor))
         {
             _dataDescriptor.Attach(OnPropertyChanged);
         }
     }
     else
     {
         _bindingProperty.Attach(OnBindingValueChanged);
     }
 }
Пример #8
0
 /// <summary>
 /// Creates a new <see cref="BindingDependency"/> object.
 /// </summary>
 /// <param name="sourceDd">Souce data descriptor for the dependency.</param>
 /// <param name="targetDd">Target data descriptor for the dependency.</param>
 /// <param name="autoAttachToSource">If set to <c>true</c>, the new dependency object will be
 /// automatically attached to the <paramref name="sourceDd"/> data descriptor. This means it will
 /// capture changes from it and reflect them on the <paramref name="targetDd"/> data descriptor.</param>
 /// <param name="updateSourceTrigger">This parameter controls, which target object event makes this
 /// binding dependency copy the target value to the <paramref name="sourceDd"/> data descriptor.
 /// If set to <see cref="UpdateSourceTrigger.PropertyChanged"/>, the new binding dependency object
 /// will automatically attach to property changes of the <paramref name="targetDd"/> data descriptor and
 /// reflect the changed value to the <paramref name="sourceDd"/> data descriptor. If set to
 /// <see cref="UpdateSourceTrigger.LostFocus"/>, the new binding dependency will attach to the
 /// <see cref="UIElement.EventOccured"/> event of the <paramref name="parentUiElement"/> object.
 /// If set to <see cref="UpdateSourceTrigger.Explicit"/>, the new binding dependency won't attach to
 /// the target at all.</param>
 /// <param name="parentUiElement">The parent <see cref="UIElement"/> of the specified <paramref name="targetDd"/>
 /// data descriptor. This parameter is only used to attach to the lost focus event if
 /// <paramref name="updateSourceTrigger"/> is set to <see cref="UpdateSourceTrigger.LostFocus"/>.</param>
 /// <param name="customValueConverter">Set a custom value converter with this parameter. If this parameter
 /// is set to <c>null</c>, the default <see cref="TypeConverter"/> will be used.</param>
 /// <param name="customValueConverterParameter">Parameter to be used in the custom value converter, if one is
 /// set.</param>
 public BindingDependency(IDataDescriptor sourceDd, IDataDescriptor targetDd, bool autoAttachToSource,
     UpdateSourceTrigger updateSourceTrigger, UIElement parentUiElement,
     IValueConverter customValueConverter, object customValueConverterParameter)
 {
   _sourceDd = sourceDd;
   _targetDd = targetDd;
   _targetObject = _targetDd.TargetObject as DependencyObject;
   _sourceObject = _sourceDd.TargetObject as DependencyObject;
   _valueConverter = customValueConverter;
   _converterParameter = customValueConverterParameter;
   if (autoAttachToSource && sourceDd.SupportsChangeNotification)
   {
     sourceDd.Attach(OnSourceChanged);
     _attachedToSource = true;
   }
   if (targetDd.SupportsChangeNotification)
   {
     if (updateSourceTrigger == UpdateSourceTrigger.PropertyChanged)
     {
       targetDd.Attach(OnTargetChanged);
       _attachedToTarget = true;
     }
     else if (updateSourceTrigger == UpdateSourceTrigger.LostFocus)
     {
       if (parentUiElement != null)
         parentUiElement.EventOccured += OnTargetElementEventOccured;
       _attachedToLostFocus = parentUiElement;
     }
   }
   // Initially update endpoints
   if (autoAttachToSource)
     UpdateTarget();
   if (updateSourceTrigger != UpdateSourceTrigger.Explicit &&
       !autoAttachToSource) // If we are attached to both, only update one direction
     UpdateSource();
 }
 /// <summary>
 /// Initializes the <see cref="ItemsControl.ItemsSource"/> property with the <see cref="SubItemsProvider"/>.
 /// </summary>
 /// <returns><c>true</c>, if the <see cref="ItemsControl.ItemsSource"/> property was changed by this method, else <c>false</c>.</returns>
 protected virtual bool InitializeSubItemsSource()
 {
   SubItemsProvider sip = SubItemsProvider;
   IEnumerable oldItemsSource = ItemsSource;
   if (!_contextChangedAttached)
   {
     ContextChanged += OnContextChanged;
     _contextChangedAttached = true;
   }
   if (_attachedContextSource != null)
     _attachedContextSource.Detach(OnDataContextValueChanged);
   _attachedContextSource = DataContext.EvaluatedSourceValue;
   _attachedContextSource.Attach(OnDataContextValueChanged);
   object context = Context;
   if (context == null)
     return false;
   ItemsSource = sip == null ? null : sip.GetSubItems(context);
   if (oldItemsSource == ItemsSource)
     return false;
   MPF.TryCleanupAndDispose(oldItemsSource);
   CheckExpandable();
   return true;
 }
 /// <summary>
 /// Attaches a change handler to the specified data descriptor
 /// <paramref name="source"/>, which will be used as binding source.
 /// </summary>
 protected void AttachToSource(IDataDescriptor source)
 {
   if (source != null && source.SupportsChangeNotification)
   {
     _attachedSource = source;
     _attachedSource.Attach(OnBindingSourceChange);
   }
 }