views:

22

answers:

1

Hi, I'm repeating same binding parameters for every textbox and they're quite long strings (which is not good for many reasons). And I'm wondering if there's a way to make them shorter?

For instance all my controls on forms are using the following binding template:

Text="{Binding SourceProperty, UpdateSourceTrigger=PropertyChanged, 
ValidatesOnExceptions=True, ValidatesOnDataErrors=True, 
NotifyOnValidationError=True}"

I'd would like to have something shorter that ideally will take SourceProperty as parameter. Possbly like this:

Text="{MyBinding SourceProperty}"

or

Text="{Binding SourceProperty, Params=MyParams}"

One possible option would be to inherit from Binding and create new markup extension. Did someone tried this? Any other ideas how to make these repetetive bindings look better?

A: 

Your first suspicion is likely correct. A custom mark-up extension might be the best bet. I would check out this article.

Charlie
that would only work if all the text properties were bound to the same item. I've fiddled with some of this and in the end I've kept using the long strings, it may not be as short as you like but at least you can look at each control and see its behavior.
Eric
Good point. I've edited my post to suggest a different option.
Charlie