Esempio n. 1
0
 /// <summary>For each element in selection either adds or removes given class.</summary>
 /// <param name="ussClass">The class that should be changed</param>
 /// <param name="hasClass">Whether the class should be added or removed.</param>
 /// <param name="onChange">Function called when the value is different from the new value. Return value can be used to delay the actual change.</param>
 public Selection <TElementType, TDataType, TParentDataType> Classed(string ussClass, bool hasClass, OnChangeCall <bool> onChange)
 {
     ChangeValue(new ClassAccessor(ussClass), hasClass, onChange);
     return(this);
 }
Esempio n. 2
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="TValueType"></typeparam>
        /// <param name="acc"></param>
        /// <param name="newValue"></param>
        /// <param name="onChange">Function (oldValue,newValue) => DDC</param>
        internal void ChangeValue <TValueType>(Accessor <TValueType> acc, TValueType newValue, OnChangeCall <TValueType> onChange)
        {
            //current value is equal to new value -> ignore
            TValueType finalExpectedValue = acc.GetValue(Element);

            //Change to this value is scheduled ?
            var lastRelevantDelayedDataChange = _delayedChanges.LastOrDefault(delayedChange => delayedChange.GetAccessor().Equals(acc));

            if (lastRelevantDelayedDataChange != null)
            {
                finalExpectedValue = ((DelayedDataChange <TValueType>)lastRelevantDelayedDataChange).NewValue;
            }

            if (EqualityComparer <TValueType> .Default.Equals(finalExpectedValue, newValue))
            {
                return;
            }

            var delayed = onChange?.Invoke(finalExpectedValue, newValue);

            if (delayed != null)
            {
                delayed.Initialize(acc, Element, finalExpectedValue, newValue);
                _delayedChanges.Add(delayed);
                if (lastRelevantDelayedDataChange == null)
                {
                    delayed.Start();
                }
            }
            else
            {
                acc.SetValue(Element, newValue);
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Generic method for changing a value of all elements of this selection to a single value.
 /// </summary>
 /// <typeparam name="T">Type of the value that is about to be changed.</typeparam>
 /// <param name="accessor">An <see cref="Accessor{T}"/>, which changes the required value</param>
 /// <param name="value">A value that is set for each element.</param>
 /// <param name="onChangeFunc">Function that is called whenever the new value is different from current value of an element. It can return a <see cref="DelayedDataChange{T}"/>, which is used to delay the actual change.</param>
 /// <returns></returns>
 public Selection <TElementType, TDataType, TParentDataType> ChangeValue <T>(Accessor <T> accessor, T value, OnChangeCall <T> onChangeFunc = null)
 {
     Groups.ForEach(group =>
     {
         TParentDataType parentData = (TParentDataType)group.GroupParent.GetBoundData();
         @group.Elements.ForEach(element =>
         {
             TDataType data = (TDataType)element.GetBoundData();
             element.GetOrCreateDataBinding().ChangeValue(accessor, value, (oldValue, newValue) => onChangeFunc?.Invoke(element, data, parentData, oldValue, newValue));
         });
     });
     return(this);
 }