DependencyObject.SetValue(DependencyProperty, Object) Method
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Sets the local value of a dependency property on a DependencyObject.
public:
virtual void SetValue(DependencyProperty ^ dp, Platform::Object ^ value) = SetValue;
void SetValue(DependencyProperty const& dp, IInspectable const& value);
public void SetValue(DependencyProperty dp, object value);
function setValue(dp, value)
Public Sub SetValue (dp As DependencyProperty, value As Object)
The identifier of the dependency property to set.
- value
-
Object
Platform::Object
IInspectable
The new local value.
If the provided value type does not match the type that is declared for the dependency property as it was originally registered, an exception is thrown.
Not all Windows Runtime properties as used by XAML are dependency properties. A DependencyProperty identifier needs to exist and it must be available as a public property of an owning object, typically the object that registered the property.
For app user-code, calling SetValue is not typically necessary. Usually, a Windows Runtime dependency property or a custom dependency property has a conventional property that wraps it, and you can just set the property value through a conventional dotted usage. Cases where you might still use SetValue are:
- You are defining a custom dependency property. You will call SetValue as part of defining your own property set accessor for a conventional property usage. For more info, see Custom dependency properties.
- You are defining a callback or are in some other scope where you are already being passed a DependencyProperty identifier, and it is possible that more than one dependency property exists that you might want to interact with in that scope. In these cases it is probably simpler to call SetValue, passing the identifier.
Product | Versions |
---|---|
WinRT | Build 10240, Build 10586, Build 14383, Build 15063, Build 16299, Build 17134, Build 17763, Build 18362, Build 19041, Build 20348, Build 22000, Build 22621, Build 26100 |