Questa documentazione è stata archiviata e non viene gestita.

Metodo DependencyObject.SetValue (DependencyPropertyKey, Object)

Sets the local value of a read-only dependency property, specified by the DependencyPropertyKey identifier of the dependency property.

Spazio dei nomi: System.Windows
Assembly: WindowsBase (in windowsbase.dll)

public void SetValue (
	DependencyPropertyKey key,
	Object value
public void SetValue (
	DependencyPropertyKey key, 
	Object value
public function SetValue (
	key : DependencyPropertyKey, 
	value : Object
Non è possibile utilizzare metodi in XAML.



The DependencyPropertyKey identifier of the property to set.


The new local value.

This signature is used when you set values for read-only dependency properties. It is uncommon that the DependencyPropertyKey is provided as part of the public API that is exposed by a type. A more common case is that SetValue(DependencyPropertyKey,Object) is being called from the type that registered that dependency property and is being used to implement the internal logic that provides the determined value for the property. For more information, see Read Only Dependency Properties.

If the provided type does not match the type that is declared for the dependency property as it was originally registered, an exception is raised. The value parameter should always be provided as the appropriate type. The exception conditions are potentially influenced by the ValidateValueCallback callback that exists on the dependency property identifier of the dependency property being set.

The following example defines a read-only dependency property, along with a public static readonly DependencyProperty that provides necessary read-only exposure to property consumers, and the get accessor for the CLR wrapper.

internal static readonly DependencyPropertyKey AquariumSizeKey = DependencyProperty.RegisterReadOnly(
  new PropertyMetadata(double.NaN)
public static readonly DependencyProperty AquariumSizeProperty =
public double AquariumSize
  get { return (double)GetValue(AquariumSizeProperty); }

Microsoft .NET Framework 3.0 è supportato in Windows Vista, Microsoft Windows XP SP2 e Windows Server 2003 SP1.

.NET Framework

Supportato in: