Saraf Talukder
Saraf Talukder

Reputation: 376

Datagrid Multiple row selection style

I have this task where the datagrid allows selecting multiple rows. When single row is selection, its style is to show 1px border around that row. Now when multiple row is selected, it should show a 1pm blue border around all the rows as a single block. So its like a box around all selected rows. Not each rows having its own border. How can I style this ?

Upvotes: 0

Views: 395

Answers (1)

Daniel Leiszen
Daniel Leiszen

Reputation: 1897

I did something similar before. You can use DataGrid.ItemContainerStyle for the purpose. You can style the ControlTemplate property for the DataGridRow (which is the type of the item container), study this blog on how to do that. In the template you should include a new Border.

The IsSelected property of the DataGridRow should be bound to some property of the model (data of the row) which can notify the viewmodel or whatever service you use to collect the selected rows. The Border which is included in the ControlTemplate should bind its StrokeThickness to the same viewmodel or service. Then you can use a Converter on that binding which uses the viewmodel or service to figure out which side of the border should be thick for that specific row.

This task is not easy, but possible. You might face some architectural challenges. I would use MVVM, DI and other patterns in order to avoid chaos.

I hope it helps.

Upvotes: 1

Related Questions