There is a Menu, for example:

<Menu> <MenuItem Header="Управление"> <MenuItem Header="Прокрутка вверх"/> <MenuItem Header="Прокрутка вниз"/> <MenuItem Header="Прокрутка влево"/> <MenuItem Header="Прокрутка вправо"/> </MenuItem> <MenuItem Header="Изображение"> <MenuItem Header="Яркость"/> <MenuItem Header="Контраст"/> <MenuItem Header="Масштаб"/> <MenuItem Header="Поворот"/> </MenuItem> </Menu> 

Can I use it also as a context menu without duplicating the code?

  • for example, so - tym32167
  • Probably I should formulate the question more precisely. I have a main menu, but I need to use it also as context. I would like to do this without duplicating the code. - 4ezy
  • Have you tried it and what did not work or did you ask without trying anything? - tym32167
  • one
    In principle, the Menu can be inserted inside the context menu, but it will look strange :) I would think aside how to reuse not the menu, but MenuItems - tym32167
  • one
    @ tym32167 MenuItem is the same control, i.e. accordingly, it can only be in one place in the tree. It is better to try to generate it somehow with templates. - Andrei NOP

1 answer 1

You can collect menu item headers into the list (in this case, apparently, it will be a List<List<string>> ) and assign it as a resource for the menu and context menu, thus avoiding duplication in xaml.