public static DependencyProperty Register(string name, Type propertyType, Type ownerType, PropertyMetadata metadata)
        {
            // Add a new list if this is the first time we've registered a property for this type
            if (!registeredPropertiesByOwner.ContainsKey(ownerType))
                registeredPropertiesByOwner.Add(ownerType, new List<DependencyProperty>());

            var existingList = registeredPropertiesByOwner[ownerType];

            // Now let's check to see if we've already registered a property with this type
            var existingProperty = existingList.FirstOrDefault(dp => dp.Name == name);
            if (existingProperty != null)
                throw new ArgumentException(string.Format("Dependency Property already registered with name {0}", name));

            var newProperty = new DependencyProperty(name, propertyType, ownerType, metadata);

            existingList.Add(newProperty);

            return newProperty;
        }
Exemple #2
0
		protected object GetValue(DependencyProperty property)
		{
			if (property == null)
				throw new ArgumentNullException("You must supply a DependencyProperty object.");

			if (!dependencyPropertyValues.ContainsKey(property.Name))
				return property.PropType.Default();

			// If we set a binding on this property, then we need to query the binding for the value, not the pass back the binding
			var obj = dependencyPropertyValues[property.Name];
			if (obj is Binding)
				return (obj as Binding).GetValue();

			// Otherwise return what's here
			return obj;
		}
Exemple #3
0
		public void SetBinding(DependencyProperty property, Binding binding)
		{
			if (property == null)
				throw new ArgumentNullException("You must supply a DependencyProperty object.");

			// We don't want to go through SetValue because we're not passing in a concrete object, we're passing in an object
			// that know's how to retrieve the item of that type.
			dependencyPropertyValues[property.Name] = binding;
		}
Exemple #4
0
		protected void SetValue(DependencyProperty property, object value)
		{
			if (property == null)
				throw new ArgumentNullException("You must supply a DependencyProperty object.");

			object oldValue = GetValue(property);

			if (!Equals(oldValue, value))
			{
				dependencyPropertyValues[property.Name] = value;

				// If the property is supposed to recalculate the the layout of the control call the InvalidateLayout
				if (property.Metadata != null && property.Metadata.AffectsLayout)
					InvalidateLayout(this);

				// Call the change handler for the property if one exists
				if (property.Metadata.OnChangeHandler != null)
					property.Metadata.OnChangeHandler(this, oldValue, value);
			}
		}