Beispiel #1
0
        internal void SetValueCore(BindableProperty property, object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes, bool forceSendChangeSignal)
        {
            bool checkAccess = (privateAttributes & SetValuePrivateFlags.CheckAccess) != 0;
            bool manuallySet = (privateAttributes & SetValuePrivateFlags.ManuallySet) != 0;
            bool silent      = (privateAttributes & SetValuePrivateFlags.Silent) != 0;
            bool fromStyle   = (privateAttributes & SetValuePrivateFlags.FromStyle) != 0;
            bool converted   = (privateAttributes & SetValuePrivateFlags.Converted) != 0;

            if (property == null)
            {
                throw new ArgumentNullException(nameof(property));
            }
            if (checkAccess && property.IsReadOnly)
            {
                Debug.WriteLine("Can not set the BindableProperty \"{0}\" because it is readonly.", property.PropertyName);
                return;
            }

            if (!converted && !property.TryConvert(ref value))
            {
                Console.WriteLine("SetValue", "Can not convert {0} to type '{1}'", value, property.ReturnType);
                return;
            }

            if (property.ValidateValue != null && !property.ValidateValue(this, value))
            {
                throw new ArgumentException("Value was an invalid value for " + property.PropertyName, nameof(value));
            }

            if (property.CoerceValue != null)
            {
                value = property.CoerceValue(this, value);
            }

            BindablePropertyContext context = GetOrCreateContext(property);

            if (manuallySet)
            {
                context.Attributes |= BindableContextAttributes.IsManuallySet;
                context.Attributes &= ~BindableContextAttributes.IsSetFromStyle;
            }
            else
            {
                context.Attributes &= ~BindableContextAttributes.IsManuallySet;
            }

            if (fromStyle)
            {
                context.Attributes |= BindableContextAttributes.IsSetFromStyle;
            }
            // else omitted on purpose

            bool currentlyApplying = _applying;

            if ((context.Attributes & BindableContextAttributes.IsBeingSet) != 0)
            {
                Queue <SetValueArgs> delayQueue = context.DelayedSetters;
                if (delayQueue == null)
                {
                    context.DelayedSetters = delayQueue = new Queue <SetValueArgs>();
                }

                delayQueue.Enqueue(new SetValueArgs(property, context, value, currentlyApplying, attributes));
            }
            else
            {
                context.Attributes |= BindableContextAttributes.IsBeingSet;
                SetValueActual(property, context, value, currentlyApplying, forceSendChangeSignal, attributes, silent);

                Queue <SetValueArgs> delayQueue = context.DelayedSetters;
                if (delayQueue != null)
                {
                    while (delayQueue.Count > 0)
                    {
                        SetValueArgs s = delayQueue.Dequeue();
                        SetValueActual(s.Property, s.Context, s.Value, s.CurrentlyApplying, forceSendChangeSignal, s.Attributes);
                    }

                    context.DelayedSetters = null;
                }

                context.Attributes &= ~BindableContextAttributes.IsBeingSet;
            }
        }
Beispiel #2
0
 public void SetValue(SetValueArgs args)
 {
     SetValue(args.StateType, args.GrainType, args.GrainReference, args.Name, args.Val);
 }