3
votes

Looking for a way to automatically verify, using unit-tests for example, that all controls in my WPF application are set to Binding.

I'm using data-binding to enable localization in the application. For example, a TextBlock control in a view will have it's Text property binding to 'SomeLocalizedLabel' property in the view model.

I need to make sure that I won't miss any control, and all my 'TextBlock' controls have their 'Text' property bound to something.

The thing that missing here is to test the View level. UI testing framework is not the solution I'm looking for, because I wish for something that can be written and executed fast.

1
I don't think that there will be an acceptable answer if you are not willing to run the app (UI tests) - because maybe you (or your MVVM framework) does the binding on runtime - or you create your controls dynamic or ... - I think in the end this will be something that your integration tests will have to handle manually or per UI tests - just my 2ctsRandom Dev
I believe this can be achive without running the app. need some way to iterate all controls in the view, and check that the 'Text'/'Content' property is set to binding and not fixed-hard coded text. This won't cover dynamically created controls. but that's not the cases i'm interested in.avivr

1 Answers

0
votes

See my post here:

You could use the mechanisms mentioned to go through all your XAML and look at the Text properties of elements, and decide if they have missed a Binding.

LocBaml is a tool that goes through the XAML to extract localizable properties....your rolling your own localization technique...but I'm sure you can adapt that to extract check "Text" properties and see if they have a binding, then produce a report where they are not.