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


C# DependencyProperty.GetMetadata方法代码示例

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


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

示例1: DependencyObjectPropertyDescriptor

 /// <summary>
 ///     Creates a new dependency property descriptor.  A note on perf:  We don't 
 ///     pass the property descriptor down as the default member descriptor here.  Doing
 ///     so takes the attributes off of the property descriptor, which can be costly if they
 ///     haven't been accessed yet.  Instead, we wait until someone needs to access our
 ///     Attributes property and demand create the attributes at that time.
 /// </summary>
 internal DependencyObjectPropertyDescriptor(DependencyProperty dp, Type ownerType)
     : base(string.Concat(dp.OwnerType.Name, ".", dp.Name), null) 
 {
     _dp = dp;
     _componentType = ownerType;
     _metadata = _dp.GetMetadata(ownerType);
 }
开发者ID:JianwenSun,项目名称:cc,代码行数:14,代码来源:DependencyObjectPropertyDescriptor.cs

示例2: RemovePropertyChanged

 public static void RemovePropertyChanged(DependencyProperty dp, DependencyObjectType type,
                                          DependencyPropertyChangedEventHandler handler)
 {
     var hcpm = dp.GetMetadata(type) as HandleChangesPropertyMetadata;
     if (hcpm == null)
         throw new ArgumentException();
     hcpm.RemovePropertyChanged(type, handler);
 }
开发者ID:xs2ranjeet,项目名称:13ns9-1spr,代码行数:8,代码来源:HandleChangesPropertyMetadata.cs

示例3: DependencyPropertyDescriptor

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

        #region Constructors

        /// <summary> 
        ///     Creates a new dependency property descriptor.  A note on perf:  We don't
        ///     pass the property descriptor down as the default member descriptor here.  Doing 
        ///     so gets the attributes off of the property descriptor, which can be costly if they 
        ///     haven't been accessed yet.  Instead, we wait until someone needs to access our
        ///     Attributes property and demand create the attributes at that time. 
        /// </summary>
        private DependencyPropertyDescriptor(PropertyDescriptor property, string name, Type componentType, DependencyProperty dp, bool isAttached) : base(name, null)
        {
            Debug.Assert(property != null || !isAttached, "Demand-load of property descriptor is only supported for direct properties"); 

            _property = property; 
            _componentType = componentType; 
            _dp = dp;
            _isAttached = isAttached; 
            _metadata = _dp.GetMetadata(componentType);
        }
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:25,代码来源:DependencyPropertyDescriptor.cs

示例4: AttachedBinding

        public AttachedBinding(DependencyObject target, FrameworkElement attachTarget,
            DependencyProperty bindingProperty, Type bindingType)
        {
            // basic checks
            if (target == null) throw new ArgumentNullException("target");
            if (attachTarget == null) throw new ArgumentNullException("attachTarget");
            if (bindingProperty == null) throw new ArgumentNullException("bindingProperty");
            if (bindingType == null) throw new ArgumentNullException("bindingType");

            // we save the reference to the source
            _target = new WeakReference(target);
            _attachTarget = new WeakReference(attachTarget);
            _bindingProperty = bindingProperty;

            // we get the default value
            object _defValue = bindingProperty.GetMetadata(bindingType).DefaultValue;

            // we attach the dp
            if (attachTarget != null)
            {
                // we create the attached property
                _attachedProperty = DependencyProperty.RegisterAttached(string.Format(DP_NAME_FROMAT, _indexer++),
                                                                        bindingType, attachTarget.GetType(),
                                                                        new PropertyMetadata(_defValue,
                                                                                             OnPropertyChanged));
            }
            else
            {
                attachTarget.Loaded += (s, e) =>
                                           {
                                               // we create the binding property
                                               _attachedProperty =
                                                   DependencyProperty.RegisterAttached(
                                                       string.Format(DP_NAME_FROMAT, _indexer++),
                                                       bindingType, attachTarget.GetType(),
                                                       new PropertyMetadata(_defValue, OnPropertyChanged));

                                               // and we if have binding then
                                               if (_binding != null) SetBinding(_binding);
                                           };
            }
        }
开发者ID:BGCX262,项目名称:zxd-svn-to-git,代码行数:42,代码来源:AttachedBinding.cs

示例5: InvalidateSubProperty

 [FriendAccessAllowed] // Built into Base, also used by Framework.
 internal void InvalidateSubProperty(DependencyProperty dp) 
 {
     // when a sub property changes, send a Changed notification with old and new value being the same, and with 
     // IsASubPropertyChange set to true 
     NotifyPropertyChange(new DependencyPropertyChangedEventArgs(dp, dp.GetMetadata(DependencyObjectType), GetValue(dp)));
 } 
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:7,代码来源:DependencyObject.cs

示例6: CoerceValue

        /// <summary>
        ///     Coerce a property value 
        /// </summary> 
        /// <param name="dp">Dependency property</param>
        public void CoerceValue(DependencyProperty dp) 
        {
            // Do not allow foreign threads access.
            // (This is a noop if this object is not assigned to a Dispatcher.)
            // 
            this.VerifyAccess();
 
            EntryIndex entryIndex = LookupEntry(dp.GlobalIndex); 
            PropertyMetadata metadata = dp.GetMetadata(DependencyObjectType);
 
            // if the property has a coerced-with-control value, apply the coercion
            // to that value.  This is done by simply calling SetCurrentValue.
            if (entryIndex.Found)
            { 
                EffectiveValueEntry entry = GetValueEntry(entryIndex, dp, metadata, RequestFlags.RawEntry);
                if (entry.IsCoercedWithCurrentValue) 
                { 
                    SetCurrentValue(dp, entry.ModifiedValue.CoercedValue);
                    return; 
                }
            }

            // IsCoerced == true && value == UnsetValue indicates that we need to re-coerce this value 
            EffectiveValueEntry newEntry = new EffectiveValueEntry(dp, FullValueSource.IsCoerced);
 
            UpdateEffectiveValue( 
                    entryIndex,
                    dp, 
                    metadata,
                    new EffectiveValueEntry() /* oldEntry */,
                    ref newEntry,
                    false /* coerceWithDeferredReference */, 
                    false /* coerceWithCurrentValue */,
                    OperationType.Unknown); 
        } 
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:39,代码来源:DependencyObject.cs

示例7: GetDefaultValue

 static object GetDefaultValue(DependencyProperty dp)
 {
     return dp.GetMetadata(typeof(SmoothStreamingMediaElement)).DefaultValue;
 }
开发者ID:bondarenkod,项目名称:pf-arm-deploy-error,代码行数:4,代码来源:AdaptivePlugin.cs

示例8: ApplyTemplatedParentValue

        internal static void ApplyTemplatedParentValue(
                DependencyObject                container,
                FrameworkObject                 child,
                int                             childIndex,
            ref FrugalStructList<ChildRecord>   childRecordFromChildIndex,
                DependencyProperty              dp,
                FrameworkElementFactory         templateRoot)
        {
            EffectiveValueEntry newEntry = new EffectiveValueEntry(dp);
            newEntry.Value = DependencyProperty.UnsetValue;
            if (GetValueFromTemplatedParent(
                    container,
                    childIndex,
                    child,
                    dp,
                ref childRecordFromChildIndex,
                    templateRoot,
                ref newEntry))

            {
                DependencyObject target = child.DO;
                target.UpdateEffectiveValue(
                        target.LookupEntry(dp.GlobalIndex),
                        dp,
                        dp.GetMetadata(target.DependencyObjectType),
                        new EffectiveValueEntry() /* oldEntry */,
                    ref newEntry,
                        false /* coerceWithDeferredReference */,
                        false /* coerceWithCurrentValue */,
                        OperationType.Unknown);
            }
        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:32,代码来源:StyleHelper.cs

示例9: IsInheritanceNode

        /// <summary> 
        ///     Determine if the current DependencyObject is a candidate for 
        ///     producing inheritable values
        /// </summary> 
        /// <remarks>
        ///     This is called by both InvalidateTree and GetValueCore
        /// </remarks>
        internal static bool IsInheritanceNode( 
            DependencyObject    d,
            DependencyProperty  dp, 
        out InheritanceBehavior inheritanceBehavior) 
        {
            // Assume can continue search 
            inheritanceBehavior = InheritanceBehavior.Default;

            // Get Framework metadata (if exists)
            FrameworkPropertyMetadata metadata = dp.GetMetadata(d.DependencyObjectType) as FrameworkPropertyMetadata; 

            // Check for correct type of metadata 
            if (metadata != null) 
            {
                FrameworkObject fo = new FrameworkObject(d); 

                if (fo.IsValid)
                {
                    // If parent is a Framework type, then check if it is at a 
                    // tree separation boundary. Stop inheritance at the boundary unless
                    // overridden by the medata.OverridesInheritanceBehavior flag. 
 
                    // GetValue from Parent only if instance is not a TreeSeparator
                    // or fmetadata.OverridesInheritanceBehavior is set to override separated tree behavior 
                    if (fo.InheritanceBehavior != InheritanceBehavior.Default && !metadata.OverridesInheritanceBehavior)
                    {
                        // Hit a tree boundary
                        inheritanceBehavior = fo.InheritanceBehavior; 
                    }
                } 
                else 
                {
                    // If not a Framework type, then, this isn't an inheritance node. 
                    // Only Framework types know how to inherit

                    return false;
                } 

                // Check if metadata is marked as inheritable 
                if (metadata.Inherits) 
                {
                    return true; 
                }
            }

            // Not a framework type with inheritable metadata 
            return false;
        } 
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:55,代码来源:TreeWalkHelper.cs

示例10: ApplyStyleOrTemplateValue

 internal static void ApplyStyleOrTemplateValue(
         FrameworkObject fo,
         DependencyProperty dp)
 {
     EffectiveValueEntry newEntry = new EffectiveValueEntry(dp);
     newEntry.Value = DependencyProperty.UnsetValue;
     if (GetValueFromStyleOrTemplate(fo, dp, ref newEntry))
     {
         DependencyObject target = fo.DO;
         target.UpdateEffectiveValue(
               target.LookupEntry(dp.GlobalIndex),
               dp,
               dp.GetMetadata(target.DependencyObjectType),
               new EffectiveValueEntry() /* oldEntry */,
               ref newEntry,
               false /* coerceWithDeferredReference */,
               false /* coerceWithCurrentValue */,
               OperationType.Unknown);
     }
 }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:20,代码来源:StyleHelper.cs

示例11: SetupPropertyChange

        /// <summary> 
        ///     Called by SetValue or ClearValue to verify that the property
        /// can be changed. 
        /// </summary> 
        private PropertyMetadata SetupPropertyChange(DependencyPropertyKey key, out DependencyProperty dp)
        { 
            if ( key != null )
            {
                dp = key.DependencyProperty;
 
                if ( dp != null )
                { 
                    dp.VerifyReadOnlyKey(key); 

                    // Get type-specific metadata for this property 
                    return dp.GetMetadata(DependencyObjectType);
                }
                else
                { 
                    throw new ArgumentException(SR.Get(SRID.ReadOnlyKeyNotAuthorized, dp.Name));
                } 
            } 
            else
            { 
                throw new ArgumentNullException("key");
            }
        }
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:27,代码来源:DependencyObject.cs

示例12: GetValueSource

        [FriendAccessAllowed] // Built into Base, also used by Core & Framework.
        internal BaseValueSourceInternal GetValueSource(DependencyProperty dp, PropertyMetadata metadata, 
                out bool hasModifiers, out bool isExpression, out bool isAnimated, out bool isCoerced, out bool isCurrent) 
        {
            if (dp == null) 
            {
                throw new ArgumentNullException("dp");
            }
 
            EntryIndex entryIndex = LookupEntry(dp.GlobalIndex);
 
            if (entryIndex.Found) 
            {
                EffectiveValueEntry entry = _effectiveValues[entryIndex.Index]; 
                hasModifiers = entry.HasModifiers;
                isExpression = entry.IsExpression;
                isAnimated = entry.IsAnimated;
                isCoerced = entry.IsCoerced; 
                isCurrent = entry.IsCoercedWithCurrentValue;
                return entry.BaseValueSourceInternal; 
            } 
            else
            { 
                isExpression = false;
                isAnimated = false;
                isCoerced = false;
                isCurrent = false; 

                if (dp.ReadOnly) 
                { 
                    if (metadata == null)
                    { 
                        metadata = dp.GetMetadata(DependencyObjectType);
                    }

                    GetReadOnlyValueCallback callback = metadata.GetReadOnlyValueCallback; 
                    if (callback != null)
                    { 
                        BaseValueSourceInternal source; 
                        callback(this, out source);
                        hasModifiers = false; 
                        return source;
                    }
                }
 
                if (dp.IsPotentiallyInherited)
                { 
                    if (metadata == null) 
                    {
                        metadata = dp.GetMetadata(DependencyObjectType); 
                    }

                    if (metadata.IsInherited)
                    { 
                        DependencyObject inheritanceParent = InheritanceParent;
                        if (inheritanceParent != null && inheritanceParent.LookupEntry(dp.GlobalIndex).Found) 
                        { 
                            hasModifiers = false;
                            return BaseValueSourceInternal.Inherited; 
                        }
                    }
                }
            } 

            hasModifiers = false; 
            return BaseValueSourceInternal.Default; 
        }
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:67,代码来源:DependencyObject.cs

示例13: InvalidateProperty

        /// <summary> 
        ///     Invalidates a property
        /// </summary>
        /// <param name="dp">Dependency property</param>
        //[CodeAnalysis("AptcaMethodsShouldOnlyCallAptcaMethods")] //Tracking Bug: 29647 
        public void InvalidateProperty(DependencyProperty dp)
        { 
            // Do not allow foreign threads access. 
            // (This is a noop if this object is not assigned to a Dispatcher.)
            // 
            this.VerifyAccess();

            if (dp == null)
            { 
                throw new ArgumentNullException("dp");
            } 
 
            EffectiveValueEntry newEntry = new EffectiveValueEntry(dp, BaseValueSourceInternal.Unknown);
 
            UpdateEffectiveValue(
                    LookupEntry(dp.GlobalIndex),
                    dp,
                    dp.GetMetadata(DependencyObjectType), 
                    new EffectiveValueEntry() /* oldEntry */,
                    ref newEntry, 
                    false /* coerceWithDeferredReference */, 
                    false /* coerceWithControlReference */,
                    OperationType.Unknown); 
        }
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:29,代码来源:DependencyObject.cs

示例14: InitializeFeaturePage

        void InitializeFeaturePage(Grid grid, DependencyProperty chooserProperty, TypographyFeaturePage page)
        {
            if (page == null)
            {
                grid.Children.Clear();
                grid.RowDefinitions.Clear();
            }
            else
            {
                // Get the property value and metadata.
                object value = GetValue(chooserProperty);
                var metadata = (TypographicPropertyMetadata)chooserProperty.GetMetadata(typeof(FontChooser));

                // Look up the sample text.
                string sampleText = (metadata.SampleTextTag != null) ? LookupString(metadata.SampleTextTag) :
                                    _defaultSampleText;

                if (page == _currentFeaturePage)
                {
                    // Update the state of the controls.
                    for (int i = 0; i < page.Items.Length; ++i)
                    {
                        // Check the radio button if it matches the current property value.
                        if (page.Items[i].Value.Equals(value))
                        {
                            var radioButton = (RadioButton)grid.Children[i * 2];
                            radioButton.IsChecked = true;
                        }

                        // Apply properties to the sample text block.
                        var sample = (TextBlock)grid.Children[i * 2 + 1];
                        sample.Text = sampleText;
                        ApplyPropertiesToObjectExcept(sample, chooserProperty);
                        sample.SetValue(metadata.TargetProperty, page.Items[i].Value);
                    }
                }
                else
                {
                    grid.Children.Clear();
                    grid.RowDefinitions.Clear();

                    // Add row definitions.
                    for (int i = 0; i < page.Items.Length; ++i)
                    {
                        var row = new RowDefinition();
                        row.Height = GridLength.Auto;
                        grid.RowDefinitions.Add(row);
                    }

                    // Add the controls.
                    for (int i = 0; i < page.Items.Length; ++i)
                    {
                        string tag = page.Items[i].Tag;
                        var radioContent = new TextBlock(new Run(LookupString(tag)));
                        radioContent.TextWrapping = TextWrapping.Wrap;

                        // Add the radio button.
                        var radioButton = new RadioButton();
                        radioButton.Name = tag;
                        radioButton.Content = radioContent;
                        radioButton.Margin = new Thickness(5.0, 0.0, 0.0, 0.0);
                        radioButton.VerticalAlignment = VerticalAlignment.Center;
                        Grid.SetRow(radioButton, i);
                        grid.Children.Add(radioButton);

                        // Check the radio button if it matches the current property value.
                        if (page.Items[i].Value.Equals(value))
                        {
                            radioButton.IsChecked = true;
                        }

                        // Hook up the event.
						radioButton.Checked += featureRadioButton_Checked;

                        // Add the block with sample text.
                        var sample = new TextBlock(new Run(sampleText));
                        sample.Margin = new Thickness(5.0, 5.0, 5.0, 0.0);
                        sample.TextWrapping = TextWrapping.WrapWithOverflow;
                        ApplyPropertiesToObjectExcept(sample, chooserProperty);
                        sample.SetValue(metadata.TargetProperty, page.Items[i].Value);
                        Grid.SetRow(sample, i);
                        Grid.SetColumn(sample, 1);
                        grid.Children.Add(sample);
                    }

                    // Add borders between rows.
                    for (int i = 0; i < page.Items.Length; ++i)
                    {
                        var border = new Border();
                        border.BorderThickness = new Thickness(0.0, 0.0, 0.0, 1.0);
                        border.BorderBrush = SystemColors.ControlLightBrush;
                        Grid.SetRow(border, i);
                        Grid.SetColumnSpan(border, 2);
                        grid.Children.Add(border);
                    }
                }
            }

            _currentFeature = chooserProperty;
            _currentFeaturePage = page;
//.........这里部分代码省略.........
开发者ID:mhusen,项目名称:Eto,代码行数:101,代码来源:fontchooser.xaml.cs

示例15: SetupPropertyChange

        /// <summary>
        ///     Called by SetValue or ClearValue to verify that the property
        /// can be changed.
        /// </summary>
        private PropertyMetadata SetupPropertyChange(DependencyPropertyKey key, out DependencyProperty dp)
        {
            if ( key != null )
            {
                dp = key.DependencyProperty;
                Debug.Assert(dp != null);

                dp.VerifyReadOnlyKey(key);

                // Get type-specific metadata for this property
                return dp.GetMetadata(DependencyObjectType);
            }
            else
            {
                throw new ArgumentNullException("key");
            }
        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:21,代码来源:DependencyObject.cs


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