コード例 #1
0
ファイル: DependencyProperty.cs プロジェクト: mildsauce45/UPF
        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;
        }
コード例 #2
0
ファイル: Control.cs プロジェクト: mildsauce45/UPF
		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;
		}
コード例 #3
0
ファイル: Control.cs プロジェクト: mildsauce45/UPF
		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;
		}
コード例 #4
0
ファイル: Control.cs プロジェクト: mildsauce45/UPF
		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);
			}
		}