ListView c TextBlock and Button



  • I'm setting up a list on the basis of the template that contains the text and ButtonButton I don't know. One problem left: How to do that Button appeared only in the line where the focus was hanging. How do I tie properties? Button.Visibility = Visible only to the element that got the focus, and the rest of it should be Collapsed♪ Here's 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"/>
    
                &lt;Button Click="PlayButton_Click" Content="Play" Height="30" Width="50" VerticalAlignment="Center" HorizontalAlignment="Center" Grid.Column="2" Visibility="Collapsed"/&gt;
            &lt;/Grid&gt;
        &lt;/DataTemplate&gt;
    &lt;/ListView.ItemTemplate&gt;
    

    </ListView>



  • Most likely:

    <ListView ItemsSource="<что у вас там>"
              HorizontalContentAlignment="Stretch"
              ScrollViewer.HorizontalScrollBarVisibility="Disabled">
        <ListView.Resources>
            <BooleanToVisibilityConverter x:Key="B2V"/>
        </ListView.Resources>
        <ListView.ItemTemplate>
            <DataTemplate>
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="300*"/>
                        <ColumnDefinition Width="100"/>
                    </Grid.ColumnDefinitions>
                    <TextBlock
                        Text="{Binding}" Height="30" Width="300" Grid.Column="0"
                        VerticalAlignment="Center" HorizontalAlignment="Left" />
                    <Button
                        Content="Play" Height="30" Width="50" Grid.Column="2"
                        VerticalAlignment="Center" HorizontalAlignment="Center"
                        Visibility="{Binding IsKeyboardFocusWithin, RelativeSource=
                                        {RelativeSource FindAncestor, AncestorType=ListViewItem},
                                      Converter={StaticResource B2V}}">
                    </Button>
                </Grid>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>
    

    (To make the Item extend over the width, it's not Binding/style,, but HorizontalContentAlignment="Stretch" ScrollViewer.HorizontalScrollBarVisibility="Disabled" On your own. ListView.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2