开发者

Shorter Binding expression with validation

开发者 https://www.devze.com 2023-01-01 23:35 出处:网络
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?

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 someon开发者_JS百科e tried this? Any other ideas how to make these repetetive bindings look better?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消