Windows apps
Collapse the table of content
Expand the table of content
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

DependencyObject.SetValue Method (DependencyPropertyKey, Object)

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

Namespace: 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
You cannot use methods 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); }

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0

Community Additions

© 2017 Microsoft