Reuse my wpf Binding factory in other code
I've got user-definable columns for my data grid, which basically boils down to a
switch(column_title)
{
case "foo": binding = new Binding("Model.Fonz");
//etc.
}
and the binding gets applied to the column.
Now I need to dump to csv, with the configured columns. As it may be a different column set that being used in my ui and I definitely don't want two huge switch statements to maintain, I'd essentially like a function lik开发者_开发百科e this:
object GetBoundProperty(object o, System.Windows.Data.Binding binding)
I won't be surprised if its obnoxiously easy, but its outside the range of my .NET knowledge at the moment and I have little desire to parse the periods out of the binding and search through reflection unless I totally have to. Thanks!
Let me suggest something else. I just don't like idea with getting data from model through databindings when you can get it directly from model... Rather than having two big switches you could create one class per column, that will handle your data requests. In pseudocode it will look like this:
ColumnData fonzColumnData = ColumnsFactory.Create(columnTitle);
// for bindings:
Binding binding = fonzColumnData.Binding;
// for CSV:
string csvData = fonzColumn.CSVData;
// ...
精彩评论