Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to add callbacks to Framework Element's Visibility Dependency Property?
    primarykey
    data
    text
    <p>I'm using a dependency property which handles the fade-in / fade-out of a Framework Element. </p> <p>The property is able to handle the fade-in / fade-out animation by registering callback methods for whenever the Visibility property of the animated element has changed.</p> <p>This was done by the previous coder as such:</p> <pre><code>UIElement.VisibilityProperty.AddOwner(typeof (FrameworkElement), new FrameworkPropertyMetadata(Visibility.Visible, VisibilityChanged, CoerceVisibility)); </code></pre> <p>The problem here is that FrameworkElement is already an owner of the VisibilityProperty, and as such triggers an exception which was catched (luckily) by ExpressionBlend.</p> <p>To counter this problem, I noticed that Dependency Properties have a "OverwriteMetadata" method, which allows someone to overwrite the metadata of a given type, in my case FrameworkElement.</p> <p>As such, I could use the following instead:</p> <pre><code>UIElement.VisibilityProperty.OverrideMetadata(typeof(FrameworkElement), new FrameworkPropertyMetadata(Visibility.Visible, VisibilityChanged, CoerceVisibility)); </code></pre> <p>My question is: </p> <p>How safe is it to overwrite FrameworkElement's Visibility's metadata ? If its unsafe, what other alternatives do I have ?</p> <p>EDIT: Well, scratch that... Apparently overwriting the metadata triggers another exception: "PropertyMetadata is already registered for type 'FrameworkElement'. </p> <p>How can I add the callback methods for the dependency property, if I'm unable to add an owner or overwrite the metadata ? </p> <p>Am I forced to create a class which derives from FrameworkElement, add it as an owner of the VisibilityProperty, and make all controls who use that property be of the same type as the derived class ?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload