This project is read-only.

Adding a dependancy/attached property to a control - sanity check

Sep 13, 2013 at 8:41 PM

My validation routine uses a tooltip to show the error. In order for that to work right, I can't specify a tooltip in the control (since that would have precedence.) So I am currently storing the tooltip in the Tag property and using a style to set the tooltip to the Tag unless there is an error.

Works just fine. But I don't want to use the Tag since I may run into a situation later where it's used some other way. So my idea is to create a bindable property just like Tooltip that can be used to hold the Tooltip so my style can swap it in/out with any error type message.

My plan is to subclass the TextBoxEx (and related) controls, add a dependency property, and then use that textbox in my applications.

But I like how you use the "Ex" approach in the SimpleView to manage things that are common to all controls and was thinking that I should consider using that approach instead. And then I thought maybe I should check with you to see if you liked either of these approaches or had a better idea on how to solve the problem.

Any and all ideas/suggestions are appreciated!
Sep 19, 2013 at 5:42 AM
I think the best approach is to use an attached property on an object you have. Let's say you create yourself an ErrorProvider class and add an attached property to it that can be added to any control, then you now have yourself a property you can arbitrarily attach to anything you want like this:
<TextBox ErrorProvider.Message="This is my message" />
<TextBox ErrorProvider.Message="{Binding BoundMessage}" />
<CheckBox ErrorProvider.Message="Must check this checkbox!" />
I always think this is a pretty elegant approach.