I have a datagrid with multiple rows. Each row has a DeleteRow button. Only the selected row should have this button. As I see it, there can be at least two solutions:
a) binding the Button Visibility property to the IsSelected property for the containing DatGridRow
or
b) using a trigger in a button only for display when the selected row is selected.
This is the code that I have for option b that does not work:
<DataGridTemplateColumn Width="50"> <DataGridTemplateColumn.CellTemplate> <DataTemplate> <Button Content="X" Tag="{Binding}" Click="DeletRow_Click" Visibility="Hidden"> <Button.Style> <Style x:Name="ButtonVisibility"> <Style.Triggers> <DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type DataGridRow}},Path=IsSelected}" Value="True"> <Setter Property= "Button.Visibility" Value="Visible"/> </DataTrigger> </Style.Triggers> </Style> </Button.Style> </Button> </DataTemplate> </DataGridTemplateColumn.CellTemplate>
This is probably very easy, but I look so closely that I am now blinding: S
Thanks
source share