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() { // 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) { }
private BooleanProperty(BooleanProperty copyMe, BooleanProperty sentinelNotUsed) : base(copyMe, sentinelNotUsed) { }
public ReadOnlyBoundToBooleanRule(Property targetProperty, BooleanProperty sourceProperty, bool inverse) : this(targetProperty.Name, sourceProperty.Name, inverse) { }