/// <summary> /// Initializes a new instance of the <see cref="DependencyPropertyValue{T}"/> class. /// </summary> /// <param name="owner">The dependency object that owns the property value.</param> /// <param name="property">The dependency property which has its value represented by this object.</param> public DependencyPropertyValue(DependencyObject owner, DependencyProperty property) { Contract.Require(owner, nameof(owner)); Contract.Require(property, nameof(property)); this.owner = owner; this.property = property; this.comparer = BindingExpressions.GetComparisonFunction(typeof(T)); this.metadata = property.GetMetadataForOwner(owner.GetType()); this.flags = DependencyPropertyValueFlags.None; this.defaultValue = (T)(metadata.DefaultValue ?? default(T)); if (typeof(T).GetInterfaces().Any(x => x == typeof(IResourceWrapper))) { flags |= DependencyPropertyValueFlags.IsResourceWrapper; } if (typeof(T).IsClass) { flags |= DependencyPropertyValueFlags.IsReferenceType; } if (typeof(T).IsValueType) { flags |= DependencyPropertyValueFlags.IsValueType; } if (metadata.HasDefaultValue && IsCoerced) { this.coercedValue = metadata.CoerceValue(owner, this.defaultValue); this.useDefaultValue = false; } UpdateRequiresDigest(GetValue()); }
/// <summary> /// Initializes a new instance of the <see cref="DependencyBoundValue{TDependency}"/> class. /// </summary> /// <param name="value">The dependency property value which created this object.</param> /// <param name="expressionType">The type of the bound expression.</param> /// <param name="dataSourceType">The type of the data source.</param> /// <param name="expression">The binding expression.</param> public DependencyBoundValue(IDependencyPropertyValue value, Type expressionType, Type dataSourceType, String expression) { this.dependencyValue = value; this.getter = (DataBindingGetter <T>)BindingExpressions.CreateBindingGetter(expressionType, dataSourceType, expression); this.setter = (DataBindingSetter <T>)BindingExpressions.CreateBindingSetter(expressionType, dataSourceType, expression); this.comparer = BindingExpressions.GetComparisonFunction(expressionType); this.cachedValue = GetUnderlyingValue(); this.dpropReference = BindingExpressions.GetSimpleDependencyProperty(dataSourceType, expression); if (dpropReference != null) { var dataSource = value.Owner.DependencyDataSource; if (dataSource != null) { HookDependencyProperty(dataSource); } } }