I have a basic ListView, whose XAML can be found below. Basically, after I populate things to it, I’d like to be able to remove them, hence the “X” button:
<ListView Name="selectedPeople" ItemsSource="{Binding Path=map, RelativeSource={RelativeSource AncestorType=Window},
Mode=OneWay}" Width="480" Height="200" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,225,10,0"
SelectionChanged="selectedPeople_SelectionChanged">
<ListView.View>
<GridView AllowsColumnReorder="True" ColumnHeaderToolTip="Broadcast call targets">
<GridViewColumn DisplayMemberBinding="{Binding Path=Key}" Header="ID" Width="120" />
<GridViewColumn DisplayMemberBinding="{Binding Path=Value}" Header="Description" Width="320" />
<GridViewColumn Header="" Width="30">
<GridViewColumn.CellTemplate>
<DataTemplate>
<Button Content=" X " Visibility="Hidden" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
I’ve left the X button invisible by default because the desired behavior is for it to only appear for rows when they are selected. How can this be done, that is changing visibility of the button on selected change? Also, once clicked, how can I relate which row/item the button was associated with?
you can change the button column template as like below with its IsEnabled Property.
or you can use the converter or trigger for visiblity.