I'm developing a control library and I would like to add "VisibleUserLevel" property to each control I create. The property is for managing user interface complexity; it is used to hide all controls with "VisibleUserLevel" < "CurrentUserLevel".
The problem I ran into is I can not override Visibility property. In Windows.Forms I would do something like this:
Because the Visibility property is a dependency property, I think you could hook into it with a CoerceValueCallback. The callback fires even before the property is updated to the new value. So, at that point you can intercept and change the new value just before the property would actually be set.
It would look like this:
public class MyTextBox : TextBox
static int VisibleUserLevel = 1; // defined here for demo purposes
static int CurrentUserLevel = 2; // defined here for demo purposes
new FrameworkPropertyMetadata(null, new CoerceValueCallback(CoerceVisibilityValue)));