protected override void OnInitialized()
        {
            Property        targetProperty = Owner[this.targetPropertyName];
            BooleanProperty sourceProperty = (BooleanProperty)Owner[this.sourceBooleanPropertyName];

            if (0 == string.Compare(targetProperty.Name, sourceProperty.Name, StringComparison.InvariantCulture))
            {
                throw new ArgumentException("source and target properties must be different");
            }

            Sync();

            sourceProperty.ValueChanged += new EventHandler(SourceProperty_ValueChanged);
        }
        protected override void OnInitialized()
        {
            if (-1 != Array.IndexOf <string>(this.targetPropertyNames, this.sourcePropertyName))
            {
                throw new ArgumentException("sourceProperty may not be in the list of targetProperties");
            }
            HashSet <string> set = null;

            foreach (LinkValuesBasedOnBooleanRule <TValue, TProperty> rule in base.Owner.Rules)
            {
                if ((rule != null) && (this != rule))
                {
                    if (set == null)
                    {
                        set = new HashSet <string>(this.targetPropertyNames);
                    }
                    HashSet <string> set2 = new HashSet <string>(rule.targetPropertyNames);
                    if (HashSetUtil.Intersect <string>(set, set2).Count != 0)
                    {
                        throw new ArgumentException("Cannot assign a property to be linked with more than one LinkValuesBasedOnBooleanRule instance");
                    }
                }
            }
            TProperty local = (TProperty)base.Owner[this.targetPropertyNames[0]];

            foreach (string str in this.targetPropertyNames)
            {
                TProperty targetProperty = (TProperty)base.Owner[str];
                if (targetProperty == null)
                {
                    throw new ArgumentException("All of the target properties must be of type TProperty (" + typeof(TProperty).FullName + ")");
                }
                if (!ScalarProperty <TValue> .IsEqualTo(targetProperty.MinValue, local.MinValue) || !ScalarProperty <TValue> .IsEqualTo(targetProperty.MaxValue, local.MaxValue))
                {
                    throw new ArgumentException("All of the target properties must have the same min/max range");
                }
                targetProperty.ValueChanged += (s, e) => ((LinkValuesBasedOnBooleanRule <TValue, TProperty>) this).OnTargetPropertyValueChanged(targetProperty, e.Value);
            }
            BooleanProperty sourceProperty = (BooleanProperty)base.Owner[this.sourcePropertyName];

            sourceProperty.ValueChanged += (s, e) => ((LinkValuesBasedOnBooleanRule <TValue, TProperty>) this).OnSourcePropertyValueChanged(sourceProperty, e.Value);
            this.Sync();
        }
 public ReadOnlyBoundToBooleanRule(Property targetProperty, BooleanProperty sourceProperty, bool inverse)
     : this(targetProperty.Name, sourceProperty.Name, inverse)
 {
 }
Ejemplo n.º 4
0
 private BooleanProperty(BooleanProperty copyMe, BooleanProperty sentinelNotUsed)
     : base(copyMe, sentinelNotUsed)
 {
 }
 public LinkValuesBasedOnBooleanRule(IEnumerable <TProperty> targetProperties, BooleanProperty sourceProperty, bool inverse) : this((from p in targetProperties select p.Name).ToArrayEx <string>(), sourceProperty.Name, inverse)
 {
 }
        protected override void OnInitialized()
        {
            // Verify the sourcePropertyName is not in targetPropertyNames
            if (-1 != Array.IndexOf(this.targetPropertyNames, this.sourcePropertyName))
            {
                throw new ArgumentException("sourceProperty may not be in the list of targetProperties");
            }

            // Verify that the intersection of this rule's targetProperty and that of all the other Link*'d rules is empty
            Set <string> ourTargetPropertyNamesSet = null;

            foreach (PropertyCollectionRule rule in Owner.Rules)
            {
                var asLinkRule = rule as LinkValuesBasedOnBooleanRule <TValue, TProperty>;

                if (asLinkRule != null && !object.ReferenceEquals(this, asLinkRule))
                {
                    if (ourTargetPropertyNamesSet == null)
                    {
                        ourTargetPropertyNamesSet = new Set <string>(this.targetPropertyNames);
                    }

                    Set <string> theirTargetPropertyNamesSet = new Set <string>(asLinkRule.targetPropertyNames);

                    Set <string> intersection = Set <string> .Intersect(ourTargetPropertyNamesSet, theirTargetPropertyNamesSet);

                    if (intersection.Count != 0)
                    {
                        throw new ArgumentException("Cannot assign a property to be linked with more than one LinkValuesBasedOnBooleanRule instance");
                    }
                }
            }

            // Verify every property is of type TProperty
            // That all the ranges are the same
            // Sign up for events
            TProperty firstProperty = (TProperty)this.Owner[this.targetPropertyNames[0]];

            foreach (string targetPropertyName in this.targetPropertyNames)
            {
                TProperty targetProperty = (TProperty)this.Owner[targetPropertyName];

                if (!(targetProperty is TProperty))
                {
                    throw new ArgumentException("All of the target properties must be of type TProperty (" + typeof(TProperty).FullName + ")");
                }

                if (!ScalarProperty <TValue> .IsEqualTo(targetProperty.MinValue, firstProperty.MinValue) ||
                    !ScalarProperty <TValue> .IsEqualTo(targetProperty.MaxValue, firstProperty.MaxValue))
                {
                    throw new ArgumentException("All of the target properties must have the same min/max range");
                }

                targetProperty.ValueChanged += new EventHandler(TargetProperty_ValueChanged);
            }

            BooleanProperty sourceProperty = (BooleanProperty)this.Owner[sourcePropertyName];

            sourceProperty.ValueChanged += new EventHandler(SourceProperty_ValueChanged);

            Sync();
        }
        // When inverse=false, the target properties will be linked when sourceProperty == true

        public LinkValuesBasedOnBooleanRule(IEnumerable <TProperty> targetProperties, BooleanProperty sourceProperty, bool inverse)
            : this(new List <TProperty>(targetProperties).ConvertAll(p => p.Name).ToArray(), sourceProperty.Name, inverse)
        {
        }