コード例 #1
0
        public static void ClearFunctionalValue(this IFunctionalTreeElement source, FunctionalProperty fp)
        {
            if (source == null)
                return;

            FunctionalPropertyManager.Instance.ClearValue(fp, source);
        }
コード例 #2
0
        public static object GetFunctionalValue(this IFunctionalTreeElement source, FunctionalProperty fp)
        {
            if (source == null)
                return false;

            return FunctionalPropertyManager.Instance.GetValue(fp, source);
        }
コード例 #3
0
        internal object GetValue(FunctionalProperty functionalProperty, IFunctionalTreeElement element)
        {
            if (element == null)
                throw new ArgumentNullException("element", "element is null.");
            if (functionalProperty == null)
                throw new ArgumentNullException("functionalProperty", "functionalProperty is null.");
            if (FunctionalPropertyValuesInternal.ContainsKey(functionalProperty) == false)
            {
                return functionalProperty.DefaultMetadata.DefaultValue;
            }

            if(!HasValue(functionalProperty, element))
            {
                //Get inherited Value
                if (functionalProperty.DefaultMetadata.Inherits)
                {
                    IFunctionalTreeElement curParent = FunctionalTreeHelper.GetFunctionalParent(element);
                    while (curParent != null)
                    {
                        if (HasValue(functionalProperty, curParent))
                            return FunctionalPropertyValuesInternal[functionalProperty][curParent];

                        curParent = FunctionalTreeHelper.GetFunctionalParent(curParent);
                    }
                }

                //Return default value
                return functionalProperty.DefaultMetadata.DefaultValue;
            }

            return FunctionalPropertyValuesInternal[functionalProperty][element];
        }
コード例 #4
0
        public FunctionalPropertyChangedEventArgs(FunctionalProperty property, Object oldValue, Object newValue)
        {
            if (property == null)
                throw new ArgumentNullException("property", "property is null.");

            Property = property;
            OldValue = oldValue;
            NewValue = newValue;
        }
コード例 #5
0
ファイル: DockingBase.cs プロジェクト: pedone/DockingLibrary
        static DockingBase()
        {
            //Register Dependency Properties
            IsEmptyProperty = DependencyProperty.Register("IsEmpty", typeof(bool), typeof(DockingBase), new UIPropertyMetadata(false));
            DockingWidthProperty = DependencyProperty.Register("DockingWidth", typeof(GridLength), typeof(DockingBase), new UIPropertyMetadata(new GridLengthConverter().ConvertFrom("*")));
            DockingHeightProperty = DependencyProperty.Register("DockingHeight", typeof(GridLength), typeof(DockingBase), new UIPropertyMetadata(new GridLengthConverter().ConvertFrom("*")));

            //Register Functional Properties
            DockManagerProperty = FunctionalProperty.Register("DockManager", typeof(DockManager), typeof(DockingBase),
                new FunctionalPropertyMetadata(null, FunctionalPropertyMetadataOptions.Inherits, DockManagerChangedHandler));

            //Register Events
            ClosedEvent = FunctionalEventManager.RegisterEvent("Closed", FunctionalStrategy.Bubble, typeof(FunctionalEventHandler), typeof(DockingBase));
        }
コード例 #6
0
        static TestingElement()
        {
            // Functional Properties
            InfoProperty = FunctionalProperty.Register("Info", typeof(string), typeof(TestingElement),
                new FunctionalPropertyMetadata("Empty", FunctionalPropertyMetadataOptions.Inherits, InfoChangedHandler, InfoCoercingHandler), InfoValidateHandler);

            // Functional Events
            BubblingTestEvent = FunctionalEventManager.RegisterEvent("BubblingTest", FunctionalStrategy.Bubble, typeof(FunctionalEventHandler), typeof(TestingElement));
            TunnelingTestEvent = FunctionalEventManager.RegisterEvent("TunnelingTest", FunctionalStrategy.Tunnel, typeof(FunctionalEventHandler), typeof(TestingElement));
            ParentTestEvent = FunctionalEventManager.RegisterEvent("ParentTest", FunctionalStrategy.Parent, typeof(FunctionalEventHandler), typeof(TestingElement));
            SiblingsTestEvent = FunctionalEventManager.RegisterEvent("SiblingsTest", FunctionalStrategy.Siblings, typeof(FunctionalEventHandler), typeof(TestingElement));
            DescendentsTestEvent = FunctionalEventManager.RegisterEvent("DescendentsTest", FunctionalStrategy.Descendents, typeof(FunctionalEventHandler), typeof(TestingElement));
            ChildrenTestEvent = FunctionalEventManager.RegisterEvent("ChildrenTest", FunctionalStrategy.Children, typeof(FunctionalEventHandler), typeof(TestingElement));
            SpreadTestEvent = FunctionalEventManager.RegisterEvent("SpreadTest", FunctionalStrategy.Spread, typeof(FunctionalEventHandler), typeof(TestingElement));
        }
コード例 #7
0
        public void ClearValue(FunctionalProperty functionalProperty, IFunctionalTreeElement element)
        {
            if (functionalProperty == null)
                throw new ArgumentNullException("functionalProperty", "functionalProperty is null.");
            if (element == null)
                throw new ArgumentNullException("element", "element is null.");

            if (FunctionalPropertyValuesInternal.ContainsKey(functionalProperty) && HasValue(functionalProperty, element))
            {
                object oldValue = FunctionalPropertyValuesInternal[functionalProperty][element];
                FunctionalPropertyValuesInternal[functionalProperty].Remove(element);

                //Fire PropertyChanged
                if (functionalProperty.DefaultMetadata.PropertyChangedCallback != null)
                {
                    functionalProperty.DefaultMetadata.PropertyChangedCallback(element,
                        new FunctionalPropertyChangedEventArgs(functionalProperty, oldValue, functionalProperty.DefaultMetadata.DefaultValue));

                    if (functionalProperty.DefaultMetadata.Inherits)
                        NotifyChildrenAboutInheritedValue(FunctionalTreeHelper.GetFunctionalChildren(element), functionalProperty, oldValue, functionalProperty.DefaultMetadata.DefaultValue);
                }
            }
        }
コード例 #8
0
        public static void SetFunctionalValue(this IFunctionalTreeElement source, FunctionalProperty fp, object value)
        {
            if (source == null)
                return;

            FunctionalPropertyManager.Instance.SetValue(fp, source, value);
        }
コード例 #9
0
        private void NotifyChildrenAboutInheritedValue(IEnumerable<IFunctionalTreeElement> children, FunctionalProperty functionalProperty, object oldValue, object newValue)
        {
            if (children == null || children.Count() == 0)
                return;

            foreach (var child in children)
            {
                if (!HasValue(functionalProperty, child))
                {
                    functionalProperty.DefaultMetadata.PropertyChangedCallback(child, new FunctionalPropertyChangedEventArgs(functionalProperty, oldValue, newValue));
                    NotifyChildrenAboutInheritedValue(FunctionalTreeHelper.GetFunctionalChildren(child), functionalProperty, oldValue, newValue);
                }
            }
        }
コード例 #10
0
 private bool HasValue(FunctionalProperty functionalProperty, IFunctionalTreeElement element)
 {
     return FunctionalPropertyValuesInternal.ContainsKey(functionalProperty) &&
         FunctionalPropertyValuesInternal[functionalProperty].ContainsKey(element);
 }
コード例 #11
0
        internal void SetValue(FunctionalProperty functionalProperty, IFunctionalTreeElement element, object value)
        {
            if (element == null)
                throw new ArgumentNullException("element", "element is null.");
            if (functionalProperty == null)
                throw new ArgumentNullException("functionalProperty", "functionalProperty is null.");
            if (value != null && functionalProperty.PropertyType.IsAssignableFrom(value.GetType()) == false)
            {
                throw new ArgumentException(String.Format("'{0}' is not a valid value for property '{1}'.", value, functionalProperty.Name));
            }

            //Validate value
            if (functionalProperty.ValidateValueCallback != null &&
                functionalProperty.ValidateValueCallback(value) == false)
            {
                throw new ArgumentException(String.Format("'{0}' is not a valid value for property '{1}'.", value, functionalProperty.Name));
            }

            //Coerce value
            object coercedValue = value;
            if (functionalProperty.DefaultMetadata.CoerceValueCallback != null)
            {
                coercedValue = functionalProperty.DefaultMetadata.CoerceValueCallback(element, value);
                if (coercedValue != value &&
                    functionalProperty.ValidateValueCallback != null &&
                    functionalProperty.ValidateValueCallback(coercedValue) == false)
                {
                    throw new ArgumentException(String.Format("'{0}' is not a valid value for property '{1}'.", coercedValue, functionalProperty.Name));
                }
            }

            //Init dictionary for functional property
            if (!FunctionalPropertyValuesInternal.ContainsKey(functionalProperty))
                FunctionalPropertyValuesInternal[functionalProperty] = new Dictionary<IFunctionalTreeElement, object>();

            //Save old value
            object oldValue = null;
            if (HasValue(functionalProperty, element))
            {
                oldValue = FunctionalPropertyValuesInternal[functionalProperty][element];
            }
            else
            {
                oldValue = functionalProperty.DefaultMetadata.DefaultValue;
            }

            //Set new value
            FunctionalPropertyValuesInternal[functionalProperty][element] = coercedValue;

            //Fire PropertyChanged
            if (functionalProperty.DefaultMetadata.PropertyChangedCallback != null)
            {
                functionalProperty.DefaultMetadata.PropertyChangedCallback(element, new FunctionalPropertyChangedEventArgs(functionalProperty, oldValue, coercedValue));
                if (functionalProperty.DefaultMetadata.Inherits)
                    NotifyChildrenAboutInheritedValue(FunctionalTreeHelper.GetFunctionalChildren(element), functionalProperty, oldValue, coercedValue);
            }
        }
コード例 #12
0
        internal FunctionalProperty Register(string name, Type propertyType, Type ownerType, FunctionalPropertyMetadata typeMetadata, ValidateValueCallback validateValueCallback)
        {
            if (String.IsNullOrEmpty(name))
                throw new ArgumentNullException("name", "name is null.");
            if (propertyType == null)
                throw new ArgumentNullException("propertyType", "propertyType is null.");
            if (ownerType == null)
                throw new ArgumentNullException("ownerType", "ownerType is null.");
            if (FunctionalPropertiesInternal.ContainsKey(ownerType))
            {
                if (FunctionalPropertiesInternal[ownerType].Any(cur => cur.Name == name))
                    throw new ArgumentException(String.Format("FunctionalProperty Name '{0}' for OwnerType '{1}' already used.", name, ownerType));
            }
            if (typeMetadata != null)
            {
                if (typeMetadata.DefaultValue != null && propertyType.IsAssignableFrom(typeMetadata.DefaultValue.GetType()) == false)
                    throw new ArgumentException(String.Format("Default value type does not match type of property '{0}'.", name));

                if (typeMetadata.DefaultValue == null && propertyType.IsValueType)
                    typeMetadata.DefaultValue = Activator.CreateInstance(propertyType);

                if (validateValueCallback != null && validateValueCallback(typeMetadata.DefaultValue) == false)
                    throw new ArgumentException(String.Format("Default value for '{0}' property is not valid because ValidateValueCallback failed.", name));
            }

            FunctionalPropertyMetadata actualMetadata = typeMetadata ?? new FunctionalPropertyMetadata(propertyType.IsValueType ? Activator.CreateInstance(propertyType) : null);
            FunctionalProperty functionalProperty = new FunctionalProperty(name, propertyType, ownerType, actualMetadata, validateValueCallback);
            if (!FunctionalPropertiesInternal.ContainsKey(ownerType))
                FunctionalPropertiesInternal[ownerType] = new List<FunctionalProperty>();

            FunctionalPropertiesInternal[ownerType].Add(functionalProperty);
            return functionalProperty;
        }