WPF ListBox ContextMenu MenuItem Command CommandParameter Path PlacementTarget

<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>

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

posted @ 2024-09-18 21:44  FredGrit  阅读(7)  评论(0编辑  收藏  举报