How can I display a button in a DataGridTemplateColumn
only when its row is selected? I've tried this, but of course there is no IsSelected
available to me. It doesn't make sense to have an IsSelected
property on the entity to which the rows are bound, and even so I wouldn't want to have to couple my DataGrid
to my model that tightly. Is there anyway that the interface can handle this itself?
This is what I have:
<sdk:DataGrid Name="_categorySummaryDataGrid"
MinHeight="200"
ItemsSource="{Binding ElementName=_userControl, Path=CategorySummaries}"
AutoGenerateColumns="False" RowDetailsVisibilityMode="VisibleWhenSelected">
<sdk:DataGrid.Columns>
<sdk:DataGridTextColumn x:Name="_nameColumn" Binding="{Binding Path=Name}" Header="Name" Width="Auto" IsReadOnly="True" />
<sdk:DataGridTextColumn x:Name="_descriptionColumn" Binding="{Binding Path=Description}" Header="Description" Width="*" IsReadOnly="True" />
<sdk:DataGridTemplateColumn x:Name="_detailsColumn" Width="Auto">
<sdk:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Content="..." ToolTipService.ToolTip="View Category Details"
Visibility="{Binding Path=IsSelected, Converter={StaticResource BooleanToVisibility}}"/>
</DataTemplate>
</sdk:DataGridTemplateColumn.CellTemplate>
</sdk:DataGridTemplateColumn>
</sdk:DataGrid.Columns>
</sdk:DataGrid>
For design reasons, I want the button to only show when the row that contains it is selected. And, if possible, I want it to show in a different way when the row is being hovered over.
There seem to be more limitations to Silverlight and WPF that I had hoped. I hope that these things are possible. Thanks. :)
Edit:
I do not have, and will not be getting Expression Blend. Thank you, that is all.
Whenever you want to change the visual appearance of anything in Silverlight, you have to think in terms of VisualStateManager. To change the appearance of a Selected DataGrid cell, you'll need to avail yourself to the wonders of VSM. By editing DataGridColumn.CellStyle's "Selected" state you can change the appearance of the selected grid cell.
Essentially this whole tutorial is about getting to the CellStyle.Template for your DataGridColumn and adding an animation to the Selected State.