We need to override a DependencyProperty
's metadata for our subclass. Now I know that I can use OverrideMetadata
and specify entirely new FrameworkPropertyMetadata
object, but for the most part I want this new metadata to be exactly the same as the existing metadata except with one additional flag set (specifically AffectsMeasure
)
My thought is to get the existing metadata, create a new metadata object, hand-copy all the members over from the old to the new (it doesn't support Clone
) changing the one I want, then use the new one in the OverrideMetadata call. But da** that is a lot of work for something otherwise so simple!
Am I missing something here?
EDIT
First things first, I meant AffectsMeasure
not AffectsRender
(which I've changed above),
BUT... I just found out our class already has the AffectsMeasure
flag set for the Width
property. The real issue is for containers of a ListBox
(e.g. a ListBoxItem
) the MeasureOverride
is only called once, when first initialized.
Since this is technically an unrelated question, I'll start a new one and close this one.
Here's the link to the new question:
Why is a ListBoxItem not calling MeasureOverride when its width is changed?