本文整理汇总了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);
}
示例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);
}
示例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);
}
示例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);
};
}
}
示例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)));
}
示例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);
}
示例7: GetDefaultValue
static object GetDefaultValue(DependencyProperty dp)
{
return dp.GetMetadata(typeof(SmoothStreamingMediaElement)).DefaultValue;
}
示例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);
}
}
示例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;
}
示例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);
}
}
示例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");
}
}
示例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;
}
示例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);
}
示例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;
//.........这里部分代码省略.........
示例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");
}
}