TargetName is not intended to be used in a style trigger collection. A style has no naming, so it makes no sense to designate elements by name. But the template (either DataTemplate or ControlTemplate) has a NameScope.
See this link.
You can do this with a DataTrigger for Button. Note that you must set the appearance of the style properties for the DataTrigger.
<Grid Name="MainGrid"> <DataGrid ItemsSource="{Binding Programs}" IsReadOnly="True" AutoGenerateColumns="false" > <DataGrid.Columns> <DataGridTextColumn Header="Name" Binding="{Binding Name}"/> <DataGridTextColumn Header="Version" Binding="{Binding Version}"/> <DataGridTextColumn Header="Publisher" Binding="{Binding Publisher}"/> </DataGrid.Columns> </DataGrid> <Button Name="ButtonExpand" Height="25" Width="25" HorizontalAlignment="Right" VerticalAlignment="Bottom" Content="+"> <Button.Style> <Style TargetType="Button"> <Setter Property="Visibility" Value="Hidden"/> <Style.Triggers> <DataTrigger Binding="{Binding ElementName=MainGrid, Path=IsMouseOver}" Value="True"> <Setter Property="Visibility" Value="Visible" /> </DataTrigger> </Style.Triggers> </Style> </Button.Style> </Button> </Grid>
Another way to do this is to associate ButtonExpand's Visibilty with the IsMouseOver DataGrid property to the converter.
Fredrik hedblad
source share