Monday, July 04, 2011

WPF 4's DataGrid - bound template columns, anybody?

I recently had occasion to use the WPF DataGrid component introduced in .NET 4. And here's something really stupid: all the built-in primitive column types (text, checkbox etc.) derive from a DataGridBoundColumn base type. This allows you to specify a binding for the cell content - very logical and WPFy.

The DataGridTemplateColumn is the sole exception. I reflected the code and noticed that they're using a ContentControl internally to present the cell - so how hard would it be to simply apply the binding to the Content property? I'll tell you how hard - it's one line of code.

It's seems like they've done more work and added an extra base class simply to make the template column less useful.


Labels: , , , ,

Configuration-driven IoC why?

I've recently gone off configuration-driven IoC in a big way. It certainly has it uses (particularly in web applications, I've found, and especially if you're selling them on). However it makes no sense at all for desktop apps. Usually you find that if you change the configuration, you're redeploying the app anyway - so why not have the configuration done centrally in code? I've never seen a non-programmer change configuration, so this costs you nothing and saves you a ton of supporting infrastructure.

Also, config-driven code tends to lead to the phenomenon of too much loose coupling. Since you have to obey the container's rules about initialization, you can't make compile-time assertions about dependencies, which can lead to a sort of "fire away and hope it's there" style of programming. And plenty of mysterious errors in apparently unrelated parts of the application.

Just my two cents, I'm not feeling particularly vehement about this one.