WPF IValueConverter and binding
People often look at WPF and XAML only for the possibility to create more appealing interface, but XAML is a lot more, because it is a way to create object with xml syntax. Here is an example on how to make some advanced binding.
Suppose I have some objects with a property called StartingTime that is a DateTime and I want to visualize the elapsed time from StartingTime to Now. Please resist the temptation to create a presentation object with a suitable property, and lets dig into IValueConverter, here is an example
|
|
This is not a good class, but is serves as example, it permits to convert from a DateTime to other object, in this example I only support elapsed that permits to me to convert DateTime values in a string representing elapsed time. Now you can use this converter without writing a single line of code, and you have full intellisense
As you can see I simply add a Binding object, sets the path to the correct property of the object bound, and I declare the converter with full intellisense power.
This can give you a taste of the power of XAML.
Alk.