I am using a RowDetailsTemplate in a Silverlight DataGrid to show row details. Setting RowDetailsVisibilityMode=”VisibleWhenSelected” does not give a good user experience (only one row can be expanded at a time, all rows cannot be collapsed). What’s the easiest way to add an expand/collapse button on each row so that the rows can be expanded/collapsed independently?
I am using a RowDetailsTemplate in a Silverlight DataGrid to show row details. Setting
Share
I’ve been meaning to blog my solution to this.
I set the grid RowDetailsVisibilityMode to Collapsed and use a DataGridTemplateColumn with a styled ToggleButton in it to toggle the row visibility.
The toggle button can be wired up to toggle the row visibility using either binding or through a TriggerAction.
Binding has to be done in code-behind since you are trying to bind ToggleButton.IsChecked to an element that is generated and does not exist in XAML (DataGridRow.DetailsVisibility)
(This will be allowed in SL5 with a stronger RelativeSource binding)
For both solutions I have this extension method in a helper class:
For code-behind binding method:
For TriggerAction method:
Then in XAML: