I am trying to get all submenu items when submenuopened event raises. I didn't find any proper solution. Can you please help me in this.
Any body please check this and give solution asap.
Hello,
You can use a recursive function to get all the subitems, for example:
List<string> allSubItems = new List<string>();
private void XamMenuItem_SubmenuOpened(object sender, EventArgs e){ StringBuilder str = new StringBuilder(); getSubItems((sender as XamMenuItem)); foreach (var element in allSubItems) str.AppendLine(element); MessageBox.Show(str.ToString());}
foreach (var element in allSubItems) str.AppendLine(element);
MessageBox.Show(str.ToString());}
public void getSubItems(XamMenuItem parentItem){ foreach (XamMenuItem item in parentItem.Items) { allSubItems.Add(item.Header.ToString()); if (item.Items.Count > 0) { getSubItems(item); } }}
You can test the code snippet in the attached sample application.
Let me know if you need any further assistance.
Sincerely,ZhivkoAssociate Software Developer
Can someone please look into this issue. The solution is not working when we use Hierarchical data template inside XamMenu. Please look into this ASAP.
When you are using the HerarchicalDataTemplate the SubmenuOpened event could be handled in DefaultItemsContainer's XamMenuItem, this way it will fire only for root level items and XamMenuItem.Items will contains your DataItem instead of XamMenuItems. In order to get all sub items you can store the root item by using the sender from SubmenuOpened. Then you can handle MouseEnter event of XamMenuItem. In the event handler you are able to check on which XamMenuItem is located the mouse and call the recursive method that will find all sub DataItems.
I have attached a sample application, where you can test this approach.
Did you have a chance to look at project I have attached in my previous response? When you use the HierarchicalItemTemplate in XamMenu you are able to handle the SubMenuOpened only in the DefaultItemsContainer's Template. It would not be raised for the XamMenuItems inside the HierarchicalDataTemplate. The XamMenuItem's Items property contains an ItemsCollection used to generate the submenus based on the ItemSource you are using. The submenu is made up of the objects within the ItemCollection(the underlying objects from the ItemSource).
I am am able handle submenu opened event. At this stage from sender(Parent XamMenu item). I am not able to get child xamMenu items.
There is field called items where it has datacontext where i am expecting list of xamMenu Items(children).
So, Please provide solution to get xamMenu Items(children)
Thanks