Message 1 of 13
WPF vb.net KeyBinding Delete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm trying to bind the Delete key to my ListView in WPF.
I want to delete items from this listview using the delete key.
Do I have the KeyBinding in the correct location? Maybe I need to activate something, I don't know.
XAML for MainWindow:
<ListView PreviewMouseLeftButtonDown="MouseLBDown" PreviewMouseMove="OnMouseBMove" Drop="MouseDrop" DragEnter="MouseDragEnter" Name="lvScrsPre" Height="145" Width="260" AllowDrop="True">
<ListView.InputBindings>
<KeyBinding Key="Delete" Command="{Binding DeleteCommand}" />
</ListView.InputBindings>
<ListView.View>
<GridView>
<GridViewColumn Width="250">
<GridViewColumn.Header>
<GridViewColumnHeader>Before Print</GridViewColumnHeader>
</GridViewColumn.Header>
<GridViewColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image Source="{Binding scrImg}" Margin="0,0,5,0" />
<TextBlock Text="{Binding scrList}" />
</StackPanel>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>Code-behind Custom class:
Public Class Scripts
Public Property scrImg As String
Public Property scrList As String
End ClassI thought this would work, but I'm just confused at this point. I think I'm doing a different approach to xml here:
Private Sub lvScrsPre_KeyDown(ByVal sender As Object, ByVal e As KeyEventArgs)
If e.Key = Key.Delete Then
If lvScrsPre.SelectedItem IsNot Nothing Then
Me.lvScrsPre.Items.Remove(lvScrsPre.SelectedItem)
End If
End If
End Sub