P
P
Pavel Kaptur2016-01-28 14:52:09
WPF
Pavel Kaptur, 2016-01-28 14:52:09

How to make different context menu for ListBox and ListBoxItem?

How to make different context menu for ListBox and ListBoxItem? Well, maybe not even a different menu, I need to have a clear all item on an empty space on the right button, and a delete item on the object.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
MrDywar Pichugin, 2016-01-28
@Dywar

WPF

<ListBox Name="ItemList" 
                                         ItemsSource="{Binding XXX}" 
                                         SelectedItem="{Binding Path=XXX, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, Mode=TwoWay}"
                                         DisplayMemberPath="XXX">
                                    <ListBox.ContextMenu>
                                        <ContextMenu>
                                            <MenuItem Header="Create" Command="{Binding CreateNewItemCommand}"/>
                                            <MenuItem Header="Clone" Command="{Binding CloneSelectedItemCommand}"/>
                                            <MenuItem Header="Delete" Command="{Binding DeleteSelectedItemCommand}"/>
                                        </ContextMenu>
                                    </ListBox.ContextMenu>
                                </ListBox>

The activity of menu buttons is determined by a property in the ViewModel named YYYCommand in .
Teams

S
Sumor, 2016-01-28
@Sumor

Well, actually, you can do it the way you want - the ListBox has its own context menu, and the elements described in the ItemTemplate have their own context menu. Menu items can be linked using commands.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question