context menu placement error
Eduardo Gomez
3,651
Reputation points
So, I have my Listview, with a context menu.
The context menu only appears f the selected item is null
The problem that I have is that the context menu will appear at the same position as where I left the mouse
For example
I want my context menu to appear in the item
like this
<ListView x:Name="Explorer"
Height="350"
Margin="20"
ItemsSource="{Binding FilesCollection}"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
SelectedItem="{Binding SelectedFile}">
<ListView.InputBindings>
<MouseBinding Command="{Binding OpenFileCommand}"
CommandParameter="{Binding SelectedFile}"
MouseAction="LeftDoubleClick" />
</ListView.InputBindings>
<Behaviors:Interaction.Triggers>
<Behaviors:EventTrigger EventName="SelectionChanged">
<Behaviors:InvokeCommandAction Command="{Binding ItemChangedCommand}"
CommandParameter="{Binding SelectedFile}" />
</Behaviors:EventTrigger>
</Behaviors:Interaction.Triggers>
<ListView.ContextMenu>
<ContextMenu Visibility="{Binding IsMenuOpen}"
PlacementTarget="{Binding ElementName=Explorer}">
<MenuItem
Command="{Binding ShareCommand}"
CommandParameter="{Binding SelectedFile}"
FocusVisualStyle="{x:Null}"
FontFamily="{StaticResource mat}"
Header="{x:Static res:Lang.Share}"
Icon="{x:Static fonts:IconFont.ShareVariantOutline}" />
<MenuItem
Command="{Binding RenameCommand}"
CommandParameter="{Binding SelectedFile}"
FocusVisualStyle="{x:Null}"
FontFamily="{StaticResource mat}"
Header="{x:Static res:Lang.Rename}"
Icon="{x:Static fonts:IconFont.RenameBox}" />
<MenuItem
Command="{Binding DeleteCommand}"
CommandParameter="{Binding SelectedFile}"
FocusVisualStyle="{x:Null}"
FontFamily="{StaticResource mat}"
Header="{x:Static res:Lang.Delete}"
Icon="{x:Static fonts:IconFont.TrashCan}" />
<MenuItem
Command="{Binding ReadCommmand}"
CommandParameter="{Binding SelectedFile}"
FocusVisualStyle="{x:Null}"
FontFamily="{StaticResource mat}"
Header="{x:Static res:Lang.Read}"
Icon="{x:Static fonts:IconFont.PlayBox}"
Visibility="{Binding IsReadVisible}" />
</ContextMenu>
In the view Model I trigger this
private void OpenMenuAction(FileItem obj) {
if (obj != null) {
IsMenuOpen = Visibility.Visible;
}
}
Developer technologies | Windows Presentation Foundation
2,854 questions
Sign in to answer