I create a list based on the template, in which the text and Button
. Button
is hidden by default. One problem remained: How to make the Button
appear only in the line on which the focus hangs (On Focused Item). How can I bind the Button.Visibility = Visible
property only to the element that received the focus, and on the rest it should be Collapsed
. Here is the code:
<ListView x:Name="FileList" VerticalAlignment="Top" SelectionChanged="FileList_SelectionChanged" Foreground="#FF00FFE8" IsItemClickEnabled="True" Grid.Row="3" IsDoubleTapEnabled="False" IsRightTapEnabled="False" Grid.ColumnSpan="2"> <ListView.ItemContainerStyle> <Style TargetType="ListViewItem"> <Setter Property="HorizontalAlignment" Value="Stretch"/> </Style> </ListView.ItemContainerStyle> <ListView.ItemTemplate> <DataTemplate> <Grid VerticalAlignment="Center" HorizontalAlignment="Stretch" Width="{Binding ElementName=FileList, Path=ActualWidth}"> <Grid.ColumnDefinitions> <ColumnDefinition Width="300*"/> <ColumnDefinition Width="100"/> </Grid.ColumnDefinitions> <TextBlock Text="{Binding}" Height="30" Width="300" VerticalAlignment="Center" HorizontalAlignment="Left" Grid.Column="0"/> <Button Click="PlayButton_Click" Content="Play" Height="30" Width="50" VerticalAlignment="Center" HorizontalAlignment="Center" Grid.Column="2" Visibility="Collapsed"/> </Grid> </DataTemplate> </ListView.ItemTemplate> </ListView>