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


C# DependencyProperty.IsValidValue方法代码示例

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


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

示例1: ApplyPropertyValue

        /// <summary>
        /// Applies a formatting property to this TextRange.
        /// </summary>
        /// <param name="formattingProperty">
        /// Property to apply.
        /// </param>
        /// <param name="value">
        /// Specifies a value for the property.
        /// </param>
        /// <param name="applyToParagraphs">
        /// This parameter is used to resolve the ambiguity for overlapping inherited properties 
        /// that apply to both inline and paragraph elements.
        /// </param>
        /// <param name="propertyValueAction">
        /// Specifies how to apply the given value - use it for setting,
        /// for increasing or for decreasing existing values.
        /// This parameter must have PropertyValueAction.SetValue for all properties that
        /// cannot be incremented or decremented by their type.
        /// </param>
        internal void ApplyPropertyValue(DependencyProperty formattingProperty, object value, bool applyToParagraphs, PropertyValueAction propertyValueAction)
        {
            Invariant.Assert(this.HasConcreteTextContainer, "Can't apply property to non-TextContainer range!");

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

            if (!TextSchema.IsCharacterProperty(formattingProperty) &&
                !TextSchema.IsParagraphProperty(formattingProperty))
            {
                #pragma warning suppress 6506 // formattingProperty is obviously not null
                throw new ArgumentException(SR.Get(SRID.TextEditorPropertyIsNotApplicableForTextFormatting, formattingProperty.Name));
            }

            // Convert property value from a string to object if needed
            if ((value is string) && formattingProperty.PropertyType != typeof(string))
            {
                System.ComponentModel.TypeConverter typeConverter = System.ComponentModel.TypeDescriptor.GetConverter(formattingProperty.PropertyType);
                Invariant.Assert(typeConverter != null);
                value = typeConverter.ConvertFromString((string)value);
            }

            // Check if the value is appropriate for the property
            if (!formattingProperty.IsValidValue(value) &&
                !(formattingProperty.PropertyType == typeof(Thickness) && (value is Thickness)))
            {
                // We exclude checking thcickness values because we have special treatment for negative values
                // in TextRangeEdit.SetParagraphProperty - negative values mean: "leave the value as is".
                throw new ArgumentException(SR.Get(SRID.TextEditorTypeOfParameterIsNotAppropriateForFormattingProperty, value == null ? "null" : value.GetType().Name, formattingProperty.Name), "value");
            }

            // Check propertyValueAction validity
            if (propertyValueAction != PropertyValueAction.SetValue &&
                propertyValueAction != PropertyValueAction.IncreaseByAbsoluteValue &&
                propertyValueAction != PropertyValueAction.DecreaseByAbsoluteValue &&
                propertyValueAction != PropertyValueAction.IncreaseByPercentageValue &&
                propertyValueAction != PropertyValueAction.DecreaseByPercentageValue)
            {
                throw new ArgumentException(SR.Get(SRID.TextRange_InvalidParameterValue), "propertyValueAction");
            }
            // Check if propertyValueAction is applicable to this property
            if (propertyValueAction != PropertyValueAction.SetValue &&
                !TextSchema.IsPropertyIncremental(formattingProperty))
            {
                throw new ArgumentException(SR.Get(SRID.TextRange_PropertyCannotBeIncrementedOrDecremented, formattingProperty.Name), "propertyValueAction");
            }

            ApplyPropertyToTextVirtual(formattingProperty, value, applyToParagraphs, propertyValueAction);
        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:70,代码来源:TextRange.cs


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