'Check All' checkbox for a WPF DataGrid, where the checkboxes already have a source?
There is a WPF DataGrid with columns that have checkboxes. These checkboxes are already bound to some data source. What we want is a checkbox for each column that checks/unchecks all the checkboxes (and as a result updates the data source so that all the values are the same).
Existing solutions on here work if there isn't an existing datasource - but we have effectively two, the 'select all' checkboxes and the actual data that the other checkboxes in the rows are bound to, if that makes sense.
If we could use a trigger or开发者_C百科 somesuch instead of 'code behind' that would be ideal. Is there a declarative solution?
Make your CheckBox's Click event point to a Command in your ViewModel that iterates your DataSource and sets IsChecked to true.
The standard solutions can work with a databound grid. An example is found (http://www.4guysfromrolla.com/articles/120810-1.aspx). This example if fully client side.
The problem comes when you postback, but that is only a problem if you are not persisting the check all back to the database and refreshing the data you are binding. In those cases, you need to ensure something is passed back to indicate the check all so you can dynamically set the boxes again after a postback.
精彩评论