Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 4
System.Windows
 CoerceValueCallback Property
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Visual Studio 2010/.NET Framework 4

Other versions are also available for the following:
.NET Framework Class Library
PropertyMetadata..::.CoerceValueCallback Property

Gets or sets a reference to a CoerceValueCallback implementation specified in this metadata.

Namespace:  System.Windows
Assembly:  WindowsBase (in WindowsBase.dll)
Visual Basic
Public Property CoerceValueCallback As CoerceValueCallback
    Get
    Set
C#
public CoerceValueCallback CoerceValueCallback { get; set; }
Visual C++
public:
property CoerceValueCallback^ CoerceValueCallback {
    CoerceValueCallback^ get ();
    void set (CoerceValueCallback^ value);
}
F#
member CoerceValueCallback : CoerceValueCallback with get, set

Property Value

Type: System.Windows..::.CoerceValueCallback
A CoerceValueCallback implementation reference.
ExceptionCondition
InvalidOperationException

Cannot set a metadata property once it is applied to a dependency property operation.

The callbacks in property metadata are not typically public members on the containing type, so the value of this property is not important for most scenarios that just consume an existing dependency property's metadata. One reason this property is exposed is so that metadata subclasses can perform their desired merge logic if both base metadata and overriding/adding metadata specify a CoerceValueCallback. However, the default merge logic for a CoerceValueCallback is to replace the previous one.

CoerceValueCallback is defined in the object model as read-write. This is so CoerceValueCallback can be adjusted after initialization of the PropertyMetadata object itself. However, once the metadata is consumed as part of a call to Register, AddOwner, or OverrideMetadata, the property system will seal that metadata instance and the properties are now considered immutable. Attempting to set CoerceValueCallback once IsSealed is true on this metadata instance will raise an exception.

.NET Framework

Supported in: 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Coerce Value and Default Values      KenParker   |   Edit   |   Show History
There is a note regarding the CoerceValueCallback not working on default values. The note reads:
NOTE:
Default values of properties are not coerced. A property value equal to the default value might occur if a property value still has its initial default, or through clearing other values with ClearValue.
I found this not to be the case from my testing. I tested using a default value for string dependency property. I also tested using ClearValue. I'm not sure if other types do not get the call back on default but it is working with strings. Perhaps they have corrected this?
Tags What's this?: Add a tag
Flag as ContentBug
Processing
© 2012 Microsoft. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker