当前位置: 首页>>代码示例>>C#>>正文


C# DependencyProperty.IsValidValue方法代码示例

本文整理汇总了C#中System.Windows.DependencyProperty.IsValidValue方法的典型用法代码示例。如果您正苦于以下问题:C# DependencyProperty.IsValidValue方法的具体用法?C# DependencyProperty.IsValidValue怎么用?C# DependencyProperty.IsValidValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.DependencyProperty的用法示例。


在下文中一共展示了DependencyProperty.IsValidValue方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DPTypeDescriptorContext

        //-----------------------------------------------------
        // 
        //  Constructors 
        //
        //----------------------------------------------------- 

        #region Constructors

        private DPTypeDescriptorContext(DependencyProperty property, object propertyValue) 
        {
            Invariant.Assert(property != null, "property == null"); 
            Invariant.Assert(propertyValue != null, "propertyValue == null"); 
            Invariant.Assert(property.IsValidValue(propertyValue), "propertyValue must be of suitable type for the given dependency property");
 
            _property = property;
            _propertyValue = propertyValue;
        }
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:17,代码来源:DPTypeDescriptorContext.cs

示例2: Condition

        /// <summary>
        ///     Constructor for creating a Condition with the given property
        /// and value instead of creating an empty one and setting values later.
        /// </summary>
        /// <remarks>
        ///     This constructor does parameter validation, which before doesn't
        /// happen until Seal() is called.  We can do it here because we get
        /// both at the same time.
        /// </remarks>
        public Condition( DependencyProperty conditionProperty, object conditionValue, string sourceName )
        {
            if( conditionProperty == null )
            {
                throw new ArgumentNullException("conditionProperty");
            }

            if( !conditionProperty.IsValidValue( conditionValue ) )
            {
                throw new ArgumentException(SR.Get(SRID.InvalidPropertyValue, conditionValue, conditionProperty.Name));
            }

            _property = conditionProperty;
            Value    = conditionValue;
            _sourceName = sourceName;
        }
开发者ID:JianwenSun,项目名称:cc,代码行数:25,代码来源:Condition.cs

示例3: SetValueCommon

        /// <summary>
        ///     The common code shared by all variants of SetValue 
        /// </summary> 
        // Takes metadata from caller because most of them have already retrieved it
        //  for their own purposes, avoiding the duplicate GetMetadata call. 
        private void SetValueCommon(
            DependencyProperty  dp,
            object              value,
            PropertyMetadata    metadata, 
            bool                coerceWithDeferredReference,
            bool                coerceWithCurrentValue, 
            OperationType       operationType, 
            bool                isInternal)
        { 
            if (IsSealed)
            {
                throw new InvalidOperationException(SR.Get(SRID.SetOnReadOnlyObjectNotAllowed, this));
            } 

            Expression newExpr = null; 
            DependencySource[] newSources = null; 

            EntryIndex entryIndex = LookupEntry(dp.GlobalIndex); 

            // Treat Unset as a Clear
            if( value == DependencyProperty.UnsetValue )
            { 
                // Parameters should have already been validated, so we call
                //  into the private method to avoid validating again. 
                ClearValueCommon(entryIndex, dp, metadata); 
                return;
            } 

            // Validate the "value" against the DP.
            bool isDeferredReference = false;
            bool newValueHasExpressionMarker = (value == ExpressionInAlternativeStore); 

            // First try to validate the value; only after this validation fails should we 
            // do the more expensive checks (type checks) for the less common scenarios 
            if (!newValueHasExpressionMarker)
            { 
                bool isValidValue = isInternal ? dp.IsValidValueInternal(value) : dp.IsValidValue(value);

                // for properties of type "object", we have to always check for expression & deferredreference
                if (!isValidValue || dp.IsObjectType) 
                {
                    // 2nd most common is expression 
                    newExpr = value as Expression; 
                    if (newExpr != null)
                    { 
                        // For Expressions, perform additional validation
                        // Make sure Expression is "attachable"
                        if (!newExpr.Attachable)
                        { 
                            throw new ArgumentException(SR.Get(SRID.SharingNonSharableExpression));
                        } 
 
                        // Check dispatchers of all Sources
                        // CALLBACK 
                        newSources = newExpr.GetSources();
                        ValidateSources(this, newSources, newExpr);
                    }
                    else 
                    {
                        // and least common is DeferredReference 
                        isDeferredReference = (value is DeferredReference); 
                        if (!isDeferredReference)
                        { 
                            if (!isValidValue)
                            {
                                // it's not a valid value & it's not an expression, so throw
                                throw new ArgumentException(SR.Get(SRID.InvalidPropertyValue, value, dp.Name)); 
                            }
                        } 
                    } 
                }
            } 

            // Get old value
            EffectiveValueEntry oldEntry;
            if (operationType == OperationType.ChangeMutableDefaultValue) 
            {
                oldEntry = new EffectiveValueEntry(dp, BaseValueSourceInternal.Default); 
                oldEntry.Value = value; 
            }
            else 
            {
                oldEntry = GetValueEntry(entryIndex, dp, metadata, RequestFlags.RawEntry);
            }
 
            // if there's an expression in some other store, fetch it now
            Expression currentExpr = 
                    (oldEntry.HasExpressionMarker)  ? _getExpressionCore(this, dp, metadata) 
                  : (oldEntry.IsExpression)         ? (oldEntry.LocalValue as Expression)
                  :                                   null; 

            // Allow expression to store value if new value is
            // not an Expression, if applicable
 
            bool handled = false;
//.........这里部分代码省略.........
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:101,代码来源:DependencyObject.cs

示例4: GetEffectiveValue

        /// <summary>
        ///     This overload of GetValue assumes that entryIndex is valid. 
        ///      It also does not do the check storage on the InheritanceParent.
        /// </summary> 
        private EffectiveValueEntry GetEffectiveValue( 
            EntryIndex          entryIndex,
            DependencyProperty  dp, 
            RequestFlags        requests)
        {
            EffectiveValueEntry entry = _effectiveValues[entryIndex.Index];
            EffectiveValueEntry effectiveEntry = entry.GetFlattenedEntry(requests); 

            if (((requests & (RequestFlags.DeferredReferences | RequestFlags.RawEntry)) != 0) || !effectiveEntry.IsDeferredReference) 
            { 
                return effectiveEntry;
            } 

            if (!entry.HasModifiers)
            {
                // For thread-safety, sealed DOs can't modify _effectiveValues. 
                Debug.Assert(!DO_Sealed, "A Sealed DO cannot be modified");
 
                if (!entry.HasExpressionMarker) 
                {
                    // The value for this property was meant to come from a dictionary 
                    // and the creation of that value had been deferred until this
                    // time for better performance. Now is the time to actually instantiate
                    // this value by querying it from the dictionary. Once we have the
                    // value we can actually replace the deferred reference marker 
                    // with the actual value.
                    DeferredReference reference = (DeferredReference)entry.Value; 
                    object value = reference.GetValue(entry.BaseValueSourceInternal); 

                    if (!dp.IsValidValue(value)) 
                    {
                        throw new InvalidOperationException(SR.Get(SRID.InvalidPropertyValue, value, dp.Name));
                    }
 
                    // Make sure the entryIndex is in [....] after
                    // the inflation of the deferred reference. 
                    entryIndex = CheckEntryIndex(entryIndex, dp.GlobalIndex); 

                    entry.Value = value; 

                    _effectiveValues[entryIndex.Index] = entry;
                    return entry;
                } 
            }
            else 
            { 
                // The value for this property was meant to come from a dictionary
                // and the creation of that value had been deferred until this 
                // time for better performance. Now is the time to actually instantiate
                // this value by querying it from the dictionary. Once we have the
                // value we can actually replace the deferred reference marker
                // with the actual value. 

                ModifiedValue modifiedValue = entry.ModifiedValue; 
                DeferredReference reference = null; 
                bool referenceFromExpression = false;
 
                if (entry.IsCoercedWithCurrentValue)
                {
                    if (!entry.IsAnimated)
                    { 
                        reference = modifiedValue.CoercedValue as DeferredReference;
                    } 
                } 

                if (reference == null && entry.IsExpression) 
                {
                    if (!entry.IsAnimated && !entry.IsCoerced)
                    {
                        reference = (DeferredReference) modifiedValue.ExpressionValue; 
                        referenceFromExpression = true;
                    } 
                } 

                Debug.Assert(reference != null, "the only modified values that can have deferredreferences are (a) expression, (b) coerced control value"); 
                if (reference == null)
                {
                    return effectiveEntry;
                } 

                object value = reference.GetValue(entry.BaseValueSourceInternal); 
 
                if (!dp.IsValidValue(value))
                { 
                    throw new InvalidOperationException(SR.Get(SRID.InvalidPropertyValue, value, dp.Name));
                }

                // Make sure the entryIndex is in [....] after 
                // the inflation of the deferred reference.
                entryIndex = CheckEntryIndex(entryIndex, dp.GlobalIndex); 
 
                if (referenceFromExpression)
                { 
                    entry.SetExpressionValue(value, modifiedValue.BaseValue);
                }
                else
//.........这里部分代码省略.........
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:101,代码来源:DependencyObject.cs

示例5: EvaluateExpression

        private EffectiveValueEntry EvaluateExpression( 
            EntryIndex entryIndex,
            DependencyProperty dp, 
            Expression expr,
            PropertyMetadata metadata,
            EffectiveValueEntry oldEntry,
            EffectiveValueEntry newEntry) 
        {
            object value = expr.GetValue(this, dp); 
            bool isDeferredReference = false; 

            if (value != DependencyProperty.UnsetValue && value != Expression.NoValue) 
            {
                isDeferredReference = (value is DeferredReference);
                if (!isDeferredReference && !dp.IsValidValue(value))
                { 
#region EventTracing
#if VERBOSE_PROPERTY_EVENT 
                    if (isDynamicTracing) 
                    {
                        if (EventTrace.IsEnabled(EventTrace.Flags.performance, EventTrace.Level.verbose)) 
                        {
                            EventTrace.EventProvider.TraceEvent(EventTrace.PROPERTYGUID,
                                                                MS.Utility.EventType.EndEvent,
                                                                EventTrace.PROPERTYVALIDATION, 0xFFF ); 
                        }
                    } 
#endif 
#endregion EventTracing
                    throw new InvalidOperationException(SR.Get(SRID.InvalidPropertyValue, value, dp.Name)); 
                }
            }
            else
            { 
                if (value == Expression.NoValue)
                { 
                    // The expression wants to "hide".  First set the 
                    // expression value to NoValue to indicate "hiding".
                    newEntry.SetExpressionValue(Expression.NoValue, expr); 

                    // Next, get the expression value some other way.
                    if (!dp.ReadOnly)
                    { 
                        EvaluateBaseValueCore(dp, metadata, ref newEntry);
                        value = newEntry.GetFlattenedEntry(RequestFlags.FullyResolved).Value; 
                    } 
                    else
                    { 
                        value = DependencyProperty.UnsetValue;
                    }
                }
 
                // if there is still no value, use the default
                if (value == DependencyProperty.UnsetValue) 
                { 
                    value = metadata.GetDefaultValue(this, dp);
                } 
            }

            // Set the expr and its evaluated value into
            // the _effectiveValues cache 
            newEntry.SetExpressionValue(value, expr);
            return newEntry; 
        } 
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:64,代码来源:DependencyObject.cs

示例6: ProcessCoerceValue

        private void ProcessCoerceValue(
            DependencyProperty dp, 
            PropertyMetadata metadata,
            ref EntryIndex entryIndex,
            ref int targetIndex,
            ref EffectiveValueEntry newEntry, 
            ref EffectiveValueEntry oldEntry,
            ref object oldValue, 
            object baseValue, 
            object controlValue,
            CoerceValueCallback coerceValueCallback, 
            bool coerceWithDeferredReference,
            bool coerceWithCurrentValue,
            bool skipBaseValueChecks)
        { 
            if (newEntry.IsDeferredReference)
            { 
                Debug.Assert(!(newEntry.IsCoerced && !newEntry.IsCoercedWithCurrentValue) && 
                    !newEntry.IsAnimated, "Coerced or Animated value cannot be a deferred reference");
 
                // Allow values to stay deferred through coercion callbacks in
                // limited circumstances, when we know the listener is internal.
                // Since we never assign DeferredReference instances to
                // non-internal (non-friend assembly) classes, it's safe to skip 
                // the dereference if the callback is to the DP owner (and not
                // a derived type).  This is consistent with passing raw 
                // DeferredReference instances to ValidateValue callbacks, which 
                // only ever go to the owner class.
                if (!coerceWithDeferredReference || 
                    dp.OwnerType != metadata.CoerceValueCallback.Method.DeclaringType) // Need 2nd check to rule out derived class callback overrides.
                {
                    // Resolve deferred references because we need the actual
                    // baseValue to evaluate the correct animated value. This is done 
                    // by invoking GetValue for this property.
                    DeferredReference dr = (DeferredReference) baseValue; 
                    baseValue = dr.GetValue(newEntry.BaseValueSourceInternal); 

                    // Set the baseValue back into the entry 
                    newEntry.SetCoersionBaseValue(baseValue);

                    entryIndex = CheckEntryIndex(entryIndex, targetIndex);
                } 
            }
 
            object coercedValue = coerceWithCurrentValue ? controlValue : coerceValueCallback(this, baseValue); 

            // Make sure that the call out did not cause a change to entryIndex 
            entryIndex = CheckEntryIndex(entryIndex, targetIndex);

            // Even if we used the controlValue in the coerce callback, we still want to compare against the original baseValue
            // to determine if we need to set a coerced value. 
            if (!Equals(dp, coercedValue, baseValue))
            { 
                // returning DependencyProperty.UnsetValue from a Coercion callback means "don't do the set" ... 
                // or "use previous value"
                if (coercedValue == DependencyProperty.UnsetValue) 
                {
                    if (oldEntry.IsDeferredReference)
                    {
                        DeferredReference reference = (DeferredReference)oldValue; 
                        oldValue = reference.GetValue(oldEntry.BaseValueSourceInternal);
 
                        entryIndex = CheckEntryIndex(entryIndex, targetIndex); 
                    }
 
                    coercedValue = oldValue;
                }

                // Note that we do not support the value being coerced to a 
                // DeferredReference
                if (!dp.IsValidValue(coercedValue)) 
                { 
                    // well... unless it's the control's "current value"
                    if (!(coerceWithCurrentValue && coercedValue is DeferredReference)) 
                        throw new ArgumentException(SR.Get(SRID.InvalidPropertyValue, coercedValue, dp.Name));
                }

                // Set the coerced value here. All other values would 
                // have been set during EvaluateEffectiveValue/GetValueCore.
 
                newEntry.SetCoercedValue(coercedValue, baseValue, skipBaseValueChecks, coerceWithCurrentValue); 
            }
        } 
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:83,代码来源:DependencyObject.cs

示例7: SetValue

        /// <summary>
        ///     Simple value set on template child
        /// </summary>
        /// <param name="dp">Dependent property</param>
        /// <param name="value">Value to set</param>
        public void SetValue(DependencyProperty dp, object value)
        {
            if (_sealed)
            {
                throw new InvalidOperationException(SR.Get(SRID.CannotChangeAfterSealed, "FrameworkElementFactory"));
            }

            if (dp == null)
            {
                throw new ArgumentNullException("dp");
            }

            // Value needs to be valid for the DP, or Binding/MultiBinding/PriorityBinding.
            //  (They all have MarkupExtension, which we don't actually support, see above check.)

            if (!dp.IsValidValue(value) && !(value is MarkupExtension) && !(value is DeferredReference))
            {
                throw new ArgumentException(SR.Get(SRID.InvalidPropertyValue, value, dp.Name));
            }

            // Styling the logical tree is not supported
            if (StyleHelper.IsStylingLogicalTree(dp, value))
            {
                throw new NotSupportedException(SR.Get(SRID.ModifyingLogicalTreeViaStylesNotImplemented, value, "FrameworkElementFactory.SetValue"));
            }

            #pragma warning suppress 6506 // dp.DefaultMetadata is never null
            if (dp.ReadOnly)
            {
                // Read-only properties will not be consulting FrameworkElementFactory for value.
                //  Rather than silently do nothing, throw error.
                throw new ArgumentException(SR.Get(SRID.ReadOnlyPropertyNotAllowed, dp.Name, GetType().Name));
            }

            ResourceReferenceExpression resourceExpression = value as ResourceReferenceExpression;
            DynamicResourceExtension dynamicResourceExtension = value as DynamicResourceExtension;
            object resourceKey = null;

            if( resourceExpression != null )
            {
                resourceKey = resourceExpression.ResourceKey;
            }
            else if( dynamicResourceExtension != null )
            {
                resourceKey = dynamicResourceExtension.ResourceKey;
            }

            if (resourceKey == null)
            {
                TemplateBindingExtension templateBinding = value as TemplateBindingExtension;
                if (templateBinding == null)
                {
                    UpdatePropertyValueList( dp, PropertyValueType.Set, value );
                }
                else
                {
                    UpdatePropertyValueList( dp, PropertyValueType.TemplateBinding, templateBinding );
                }
            }
            else
            {
                UpdatePropertyValueList(dp, PropertyValueType.Resource, resourceKey);
            }
        }
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:69,代码来源:FrameworkElementFactory.cs

示例8: SetValue

        private void SetValue(DependencyProperty dependencyProperty, DependencyPropertyKey dependencyPropertyKey, object value, bool setCurrentValue = false, BaseValueSource source = BaseValueSource.Unknown)
        {
            VerifyReadOnlyProperty(dependencyProperty, dependencyPropertyKey);

            IExpressionProvider newExpressionProvider = value as IExpressionProvider;
            if (newExpressionProvider == null && !dependencyProperty.IsValidValue(value))
            {
                return; // invalid value
            }

            IDependencyPropertyValueEntry entry = GetInitializedValueEntry(dependencyProperty);

            IExpression oldExpression = setCurrentValue ?
                entry.GetBaseValue(false) as IExpression : // current value may be set in the top priority expression
                entry.GetBaseValue((int)source, false) as IExpression;

            if (newExpressionProvider != null)
            {
                value = newExpressionProvider.CreateExpression(this, dependencyProperty);
            }
            else if (oldExpression != null && oldExpression.SetValue(value))
            {
                return; // value (current or not) was set in the existing expression, nothing else to do
            }

            if (setCurrentValue)
            {
                entry.SetCurrentValue(value);
                return; // base value isn't changed
            }

            if (oldExpression is IDisposable) // expression is being replaced
            {
                ((IDisposable)oldExpression).Dispose();
            }

            entry.SetBaseValue((int)source, value);
            entry.ClearCurrentValue();
        }
开发者ID:highzion,项目名称:Granular,代码行数:39,代码来源:DependencyObject.cs

示例9: ConvertValue

        static object ConvertValue(object value, DependencyProperty dp, out Exception e) 
        { 
            object result;
            e = null; 

            if (value == DependencyProperty.UnsetValue || dp.IsValidValue(value))
            {
                result = value; 
            }
            else 
            { 
                result = null;  // placeholder to keep compiler happy
                // if value isn't the right type, use a type converter to get a better value 
                bool success = false;
                TypeConverter converter = DefaultValueConverter.GetConverter(dp.PropertyType);
                if (converter != null && converter.CanConvertFrom(value.GetType()))
                { 
                    // PreSharp uses message numbers that the C# compiler doesn't know about.
                    // Disable the C# complaints, per the PreSharp documentation. 
                    #pragma warning disable 1634, 1691 

                    // PreSharp complains about catching NullReference (and other) exceptions. 
                    // It doesn't recognize that IsCriticalException() handles these correctly.
                    #pragma warning disable 56500

                    try 
                    {
                        result = converter.ConvertFrom(null, CultureInfo.InvariantCulture, value); 
                        success = dp.IsValidValue(result); 
                    }
 
                    // Catch all exceptions.  If we can't convert the fallback value, it doesn't
                    // matter why not;  we should always use the default value instead.
                    // (See bug 1853628 for an example of a converter that throws
                    // an exception not mentioned in the documentation for ConvertFrom.) 
                    catch (Exception ex)
                    { 
                        e = ex; 
                    }
                    catch // non CLS compliant exception 
                    {
                    }

                    #pragma warning restore 56500 
                    #pragma warning restore 1634, 1691
                } 
 
                if (!success)
                { 
                    // if can't convert it, don't use it
                    result = DefaultValueObject;
                }
            } 

            return result; 
        } 
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:56,代码来源:BindingExpressionBase.cs

示例10: SetValue

        private void SetValue(DependencyProperty dependencyProperty, DependencyPropertyKey dependencyPropertyKey, object value, BaseValueSource source)
        {
            VerifyReadOnlyProperty(dependencyProperty, dependencyPropertyKey);

            IExpressionProvider newExpressionProvider = value as IExpressionProvider;
            if (newExpressionProvider == null && !dependencyProperty.IsValidValue(value))
            {
                return;
            }

            IDependencyPropertyValueEntry entry = GetInitializedValueEntry(dependencyProperty);

            IExpression oldExpression = entry.GetBaseValue((int)source, false) as IExpression;

            if (newExpressionProvider != null)
            {
                value = newExpressionProvider.CreateExpression(this, dependencyProperty);
            }
            else if (oldExpression != null && oldExpression.SetValue(value))
            {
                return;
            }

            if (oldExpression is IDisposable)
            {
                ((IDisposable)oldExpression).Dispose();
            }

            entry.SetBaseValue((int)source, value);
        }
开发者ID:diab0l,项目名称:Granular,代码行数:30,代码来源:DependencyObject.cs

示例11: SetValue

        /// <summary>Sets the value of a dependency property.</summary>
        /// <param name="dp">The dependency property identifier of the property to set.</param>
        /// <param name="value">The new value.</param>
        public void SetValue(DependencyProperty dp, object value)
        {
            if ([email protected])
            {
                throw new InvalidOperationException("Can't change FrameworkElementFactory after sealed");
            }
            if (dp == null)
            {
                throw new ArgumentNullException("dp");
            }
            if (!dp.IsValidValue(value) && !(value is MarkupExtension) && !(value is DeferredReference) && !(value is BindingBase))
            {
                object[] objArray1 = new object[] { value, dp.Name };
                throw new ArgumentException("InvalidPropertyValue");
            }

            /*
            //if (StyleHelper.IsStylingLogicalTree(dp, value))
            //{
            //    throw new NotSupportedException("ModifyingLogicalTreeViaStylesNotImplemented");
            //}
            */

            if (dp.ReadOnly)
            {
                throw new ArgumentException("ReadOnlyPropertyNotAllowed");
            }
            ResourceReferenceExpression resourceReferenceExpression = value as ResourceReferenceExpression;
            object resourceKey = null;
            if (resourceReferenceExpression != null)
            {
                resourceKey = resourceReferenceExpression.ResourceKey;
            }
            if (resourceKey != null)
            {
                this.UpdatePropertyValueList(dp, PropertyValueType.Resource, resourceKey);
                return;
            }
            TemplateBindingExtension templateBindingExtension = value as TemplateBindingExtension;
            if (templateBindingExtension != null)
            {
                this.UpdatePropertyValueList(dp, PropertyValueType.TemplateBinding, templateBindingExtension);
                return;
            }
            this.UpdatePropertyValueList(dp, PropertyValueType.Set, value);
        }
开发者ID:evnik,项目名称:UIFramework,代码行数:49,代码来源:FrameworkElementFactory.cs

示例12: GetChildValueHelper


//.........这里部分代码省略.........
                                // Try to freeze the value
                                SealIfSealable(value);
                            }
                            else
                            {
                                value = valueLookupList.List[i].Value;
                            }
                        }
                    }
                    break;

                case ValueLookupType.TemplateBinding:
                    {
                        TemplateBindingExtension templateBinding = (TemplateBindingExtension)valueLookupList.List[i].Value;
                        DependencyProperty sourceProperty = templateBinding.Property;

                        // Direct binding of Child property to Container
                        value = container.GetValue(sourceProperty);

                        // Apply the converter, if any
                        if (templateBinding.Converter != null)
                        {
                            DependencyProperty targetProperty = valueLookupList.List[i].Property;
                            System.Globalization.CultureInfo culture = child.Language.GetCompatibleCulture();

                            value = templateBinding.Converter.Convert(
                                                value,
                                                targetProperty.PropertyType,
                                                templateBinding.ConverterParameter,
                                                culture);
                        }

                        // if the binding returns an invalid value, fallback to default value
                        if ((value != DependencyProperty.UnsetValue) && !dp.IsValidValue(value))
                        {
                            value = DependencyProperty.UnsetValue;
                        }
                    }
                    break;

                case ValueLookupType.Resource:
                    {
                        // Resource lookup
                        object source;
                        value = FrameworkElement.FindResourceInternal(
                                        child.FE,
                                        child.FCE,
                                        dp,
                                        valueLookupList.List[i].Value,  // resourceKey
                                        null,  // unlinkedParent
                                        true,  // allowDeferredResourceReference
                                        false, // mustReturnDeferredResourceReference
                                        null,  // boundaryElement
                                        false, // disableThrowOnResourceNotFound
                                        out source);

                        // Try to freeze the value
                        SealIfSealable(value);
                    }
                    break;
                }

                // See if value needs per-instance storage
                if (value != DependencyProperty.UnsetValue)
                {
                    entry.Value = value;
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:67,代码来源:StyleHelper.cs


注:本文中的System.Windows.DependencyProperty.IsValidValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。