I'm trying to add a PropertyChangedCallback to UIElement.RenderTransformOriginProperty. An exception is thrown when I try to override the PropertyMetadata.
I have searched MSDN and Google, and all I have been able to come up with is this. DependencyPropertyDescriptor.AddValueChanged is suggested at some point in that post, but that won't solve my problem since this is not a per-instance callback.
I don't understand what this exception means at all. Does anyone know what I am doing wrong?
public class foo : FrameworkElement
{
private static void Origin_Changed( DependencyObject d,
DependencyPropertyChangedEventArgs e)
{ }
static foo()
{
PropertyMetadata OriginalMetaData =
UIElement.RenderTransformOriginProperty.GetMetadata(
typeof(FrameworkElement));
/*An exception is thrown when this line is executed:
"Cannot change property metadata after it has been associated with a property"*/
OriginalMetaData.PropertyChangedCallback +=
new PropertyChangedCallback(Origin_Changed);
UIElement.RenderTransformOriginProperty.OverrideMetadata(
typeof(foo), OriginalMetaData);
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…