On May 5, 5:21*am, "Gobi" <gobinat...@yahoo.com> wrote:
> Hi,
>
> I have few UI elements shown in a main frame. When selecting a UI elementI
> want to show a context menu. Used a command pattern for it with the UI
> element publishing it's commands and it works fine.
>
> Now when two or more UI elements are selected and we want to show the
> context menu, we need a subset of these menus
>
> 1) only menus common to both
> 2) some menus can be common to both but doesn't make sense to show for
> multiple selection(e.g. When two are selected we should NOT show rename,
> though both of them have rename)
>
> I'm looking at the same functionality of Visual studio, where we get
> different context menus when we select one project in the visual studio vs
> when we select multiple project in visual studio.
>
> Is there a pattern for the same.
Doing #1 is fairly straightforward - just intersect the command lists
of all selected items.
Doing #2 is probably less so, but the most generic way I can think of
handling this is to add a "CanExecute" method to your ICommand (or
whatever it is called), which is invoked with sequence of selected
elements passed as an argument. Then you can return false from that
method on RenameCommand if there's more than one element, for example.
And use that when building the context menu.
|