Binding an object to data grid cell - conditional cell style

前端 未结 1 1526
长发绾君心
长发绾君心 2021-01-28 07:49

TL;DR: if a DataGrid cell is bound to a specific object (not string, int, ...), how can I access it in converter or setter?

相关标签:
1条回答
  • 2021-01-28 08:44

    You can't really store the Person object in the DataRow. You can confirm this yourself:

    var dr = dt.NewRow();
    //set the Name column to a Person object
    dr["Name"] = new Person(name, age >= 18);
    //...and retrieve it. It is now a string:    
    var thePerson = dr["Name"] as string;
    

    Mixing an object model with a DataTable is not a good idea. You should replace the DataTable with a collection of custom objects. Then you will be able to use a value converter or a DataTrigger to set the Background property of the cell.

    0 讨论(0)
提交回复
热议问题