Gitea Repo
I have a WPF C# Application with a ListView
and there inside is a GridView
.
<ListView Name="Entries">
<ListView.View>
<GridView AllowsColumnReorder="False">
<GridView.ColumnHeaderContainerStyle>
<Style TargetType="{x:Type GridViewColumnHeader}">
<Setter Property="IsHitTestVisible" Value="False"/>
</Style>
</GridView.ColumnHeaderContainerStyle>
<GridViewColumn Header="Type" Width="Auto" DisplayMemberBinding="{Binding Type}" />
<GridViewColumn Header="Title" Width="Auto" DisplayMemberBinding="{Binding Title}" />
<GridViewColumn Header="Date" Width="Auto" DisplayMemberBinding="{Binding Date}" />
<GridViewColumn Header="Tags" Width="Auto" DisplayMemberBinding="{Binding Tags}" />
<GridViewColumn Header="Categories" Width="Auto" DisplayMemberBinding="{Binding Categories}" />
</GridView>
</ListView.View>
</ListView>
When I right click on of the ListViewItem
s, a ContextMenu
should come up and when I click on it, it should execute a function.
Something like this:
private void EntryClick(<identifier of click>) {
MessageBox.Show("Clicked " + <maybe title to identify what i clicked>);
}
Everywhere I found this, but I don't know what to do with it:
<MenuItem ... CommandParameter="{Binding SelectedItem, RelativeSource={RelativeSource FindAncestor,ListBox,1}} />
Then I found this: WPF Get name of ListView item when ContextMenu clicked But I don't anything for item.Name
Edit:
I added
<ListView.ContextMenu>
<ContextMenu>
<MenuItem Header="Remove"
Command="{Binding RemoveItem}"
CommandParameter="{Binding RelativeSource={RelativeSource AncestorType=ContextMenu}, Path=PlacementTarget.SelectedItem}" />
</ContextMenu>
</ListView.ContextMenu>
and
using GalaSoft.MvvmLight.Command;
private ICommand _removeItem;
public ICommand RemoveItem
{
get { return _removeItem ?? (_removeItem = new RelayCommand(p => RemoveItemCommand((string)p))); }
}
private void RemoveItemCommand(string item)
{
if (!string.IsNullOrEmpty(item))
MessageBox.Show(item);
}
But now I get this error:
Delegate System.Action does not take 1 arguments
I installed the NuGet package GalaSoft.MvvmLight
because I didn't have RelayCommand
. Was this right or do I have to create a class?