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.
Can you please check and let me know.
I am looking for a solution where i will get list of submenuitems(XamMenuItems).
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
Any body please check this and give solution asap.