How to dynamically add MenuItems (with a header) to a WPF menu

后端 未结 2 1794
星月不相逢
星月不相逢 2021-02-02 01:39

[Edit #3] - to anyone reading this question: do not under any circumstance use the approach outlined in this question. It is a Coding Horr

2条回答
  •  北海茫月
    2021-02-02 02:25

    Another possible approach could be having the Menu be a region and agree on a convention so all views added to that region have a ViewModel with a property named MenuHeader. That way, the region adapter can simply get the menu header from the View's Data Context, and set it to the item when adding it.

    Something similar is done in Prism with views added to a Tab Region. You can read more here.

    I hope this provides some useful guidance.

    Thanks, Damian

提交回复
热议问题