For illustrative purposes, say I wanted to create a subclass of the WPF TextBox called BizarroTextBox where the IsReadOnly property has the reverse effect of its default behavior.
Now normally in the non-WPF world, for a hypothetical 'TextBox' control, it would be relatively trivial...
public class BizarroTextBox : TextBox
{
public override bool IsReadOnly
{
get{ return !base.IsReadOnly; }
set{ base.IsReadOnly = !value; }
}
}
...but I'm not sure how to/if it's even possible to do something similar when dealing with DependencyObjects and DependencyProperties.
While I could re-define the property's metadata in my subclass and use a Coalesce function to invert the value on the way in, I don't know of a way to invert it on the way back out.
You also can't simply use an bool-inverting converter either as there's only one object which can't be both the source and target unless you're connecting two different properties, which we're not.
You can't do it in the CLR getter/setters either as they are convenience methods which are bypassed when using bindings.
It would be so much easier if they had a coalesce-on-the-way-back-out method but I'm not aware of any such thing. So can this be done?