I have a datagrid with a number ow rows. Every row has as DeleteRow-button. Only the row that is selected should have this button visible. As I see it there may be at least two solutions:
a) binding the Visibility-property of the button to the IsSelected-property of the containing DatGridRow
or
b) using a trigger in the button to only be visible when the containing row is selected.
This is the code I have for option b, which isn't working:
<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>
It's probably really easy but I've been staring so much it's blinding me now :S
Thanks