I am using the Infragistics XamDateTimeEditor control and I want to add a dependency property to it to allow the developer to choose to have all the text selected when the control gets focus. I have created a style that is used to set the behavior I want but I want the developer to decide if the behavior should be executed based on a boolean dependency property. I am not sure how that is done.
I am using the Infragistics XamDateTimeEditor control and I want to add a dependency
Share
I assume you inherited from XamDateTimeEditor for this.
If you can write the code referencing a “standard” (clr) property, then you are good to go:
remove your backing field and replace the implementation of the standard property so that it accesses the DependencyProperty instead of the backing field.
Then, when you access IsSelectOnFocusEnabled in your code it will return the current value of the Dependency Property.
You can also set it up to receive notification whenever the property changes, but I don’t see why you would in your case.
There is also another option for this trick, which uses no inheritance and an attached property if you’d like.
UPDATE:
OK, since it was requested, here’s a way to achieve that for any textbox. It should be easy to translate to whatever event you use to carry that out on another type of control.
The way you use it is as follows, for example:
This shows you how to set up the property to activate the behavior, and how to bind it to something else if need be.
Note that this specific example is not perfect (if you tab through it works, if you click inside the control, the textbox has internal logic that actually deselects the text, but that’s just an example on how to attach behaviors to controls through attached properties).