1. 程式人生 > 實用技巧 >ListBox裡的MenuItem選單動態引數傳入

ListBox裡的MenuItem選單動態引數傳入

                                <ListBox.ContextMenu>
                                    <ContextMenu>
                                        <MenuItem
                                            Command="{Binding AddTrackListCommand}"
                                            CommandParameter
="{Binding RelativeSource={RelativeSource AncestorType={x:Type ContextMenu}}, Path=PlacementTarget.SelectedItem}" Header="加入軌跡列表" /> <MenuItem Command="{Binding AddFavorityCommand}" Header="{DynamicResource G_616}
" /> <MenuItem Command="{Binding SaveImageCommand}" Header="{DynamicResource G_31}" /> </ContextMenu> </ListBox.ContextMenu>
ListBox裡的MenuItem選單綁定當前選擇的item,並傳入viewmodel,

後臺程式碼
public ICommand AddTrackListCommand { get { return new DelegateCommand<object>(AddTrackList); } }