<ListBox.ContextMenu> <ContextMenu> <MenuItem Header="Export NewtonSoftJson" FontSize="50" Foreground="Red" Command="{Binding ExportNewtonJsonCmd}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type ContextMenu}},Path=PlacementTarget}"/> <MenuItem Header="Export BinaryFormatter" FontSize="50" Foreground="Red" Command="{Binding ExportBinaryFormatterCmd}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ContextMenu}},Path=PlacementTarget}"/> </ContextMenu> </ListBox.ContextMenu>
标签:PlacementTarget,CommandParameter,ContextMenu,Command,MenuItem,Path From: https://www.cnblogs.com/Fred1987/p/18419388