Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
2085
Can you have both XamMenuItems and XamMenuSeparators in the same collection?
posted

Hi,

I'm trying to dynamically build a XamContextMenu's XamMenuItems based on some properties of the row/cell that was clicked on in a XamDataGrid.

Based on what properties exist on my row item, I need to dynamically add several groups of XamMenuItems.  I am initially using a List<XamMenuItem> to hold all the items that I need to add to the menu, but I would like to put XamMenuSeperators between the different 'groups' of my XamMenuItems.  However, XamMenuSeparator is not derived from XamMenuItem and I am not sure if there is a collection that would allow me to combine XamMenuItems and XamMenuSeparators such that I could iterate over the collection and add items to my XamContextMenu dynamically?

Thank you

Parents
  • 1500
    Verified Answer
    Offline posted

    Hello,

    If could suggest using a Dictionary instead, where you would have a key - group and value - list of menu items. 

    Using two foreach loops, one for the groups, one for the lists inside, and adding a separator when a group has been iterated.

    I don't know how you populate your list and how you determine which item goes into what group, but I believe my suggestion should be efficient.

    Having different types in the same list is not going to work well with c#, even though there are workarounds.

    Please let me know if you have more questions.

    Sincerely,
    Tihomir Tonev
    Associate Software Developer
    Infragistics

Reply Children
No Data