DataGrid and Observable Collection in WPF

前端 未结 2 1737
误落风尘
误落风尘 2021-01-19 03:45

I have a datagrid like below in my WPF application.



        
2条回答
  •  盖世英雄少女心
    2021-01-19 04:25

    When creating your own UI in DataGridTemplateColumn (or a custom DataGrid.RowStyle for that matter), the DataGrid changes the UpdateSourceTrigger (i.e. when the underlying data should be updated) on all your bindings to Explicit if you didn't specify them yourself.

    That "feature" is described briefly here: 5 Random Gotchas with the WPF DataGrid, and even though the author says this happens whether or not you set the UpdateSourceTrigger yourself, setting it yourself does actually work (at least in .Net 4.0).

    Use LostFocus to mimic the default TextBox behavior (and PropertyChanged on CheckBox etc):

    ...
    
    ...
    
    ...
    

提交回复
热议问题