This project is read-only.

WPF Menu Problem

Dec 14, 2009 at 12:21 PM
Edited Dec 15, 2009 at 7:14 AM



1. MenuItem seems not to be a single class but in the ControlType to UIItem Mapping I read ControlType= MenuItem UIItem=MenuItem. The class MenuItem does not exist.


structure for a submenu (WPF)

Tree in AutomationVerify

window (MainWindow)

  •  window (Mainwindow)
    • window (no name no automationID)
      • menu (no name, automationId exist)
        • menuItem ("Hinzufügen") (has a subMenu)
        • menuItem
      • window (no name no automationID) (the submenu of "Hinzufügen))
        • menuItem (this is the Item I search)

I need the element in the submenu but White does not found it :(

Dec 14, 2009 at 8:09 PM

MenuItem is secondary element. So you should first get the Menu and then try to reach the menu item within.

Dec 15, 2009 at 7:38 AM

yes I know this


the code I use

I don't know why but the upcoming context menu is a MenuBar (maybe an error of our developer?). This menu will open if I press on a split button

(see link)


to get the "Hinzufügen" MenuItem



MenuBar bar = window.Get<MenuBar>(SearchCriteria.ByControlType(ControlType.MenuBar).AndAutomationId("id");

Menu menuItem = bar.TopLevelMenu.Where(p=>p.Name=="Hinzufügen");



menuItem has not operation "MenuItem" ChildMenu is null.


implementation in application to add submenu=>




/// <summary>

  /// Custom implementation of a MenuItem.

  /// </summary>

  public class MyMenuItem : MenuItem


    static MyMenuItem()


      //DefaultStyleKeyProperty.OverrideMetadata(typeof(KnxMenuItem), new FrameworkPropertyMetadata(typeof(KnxMenuItem)));








/// <summary>
/// Sets the add menu.
/// </summary>
/// <param name="collection">The collection.</param>
/// <param name="contents">The ContentType.</param>
/// <returns>Return true if a item was added to the collection. Only to a item in the tree.</returns>
internal bool SetAddMenu(ItemCollection collection, Contents contents)
      bool collectionWasSet = false;

      if (this.selectedItem != null)
        if (selectedItem is IBuildingPart)
          IBuildingPart buildingPart = (IBuildingPart) selectedItem;

          //MyMenuItem trade = GetMenuItem(typeof (ITrade), Properties.Resources.Trades);

          MyMenuItem buildings = GetMenuItem(BuildingPartType.Building, Properties.Resources.Buildings);

          //MySeparator seperator = new MySeparator();

           MyMenuItem buildingParts = GetMenuItem(BuildingPartType.BuildingPart, Properties.Resources.BuildingParts);

           MyMenuItem stairways = GetMenuItem(BuildingPartType.Stairway, Properties.Resources.Stairways);

           MyMenuItem floors = GetMenuItem(BuildingPartType.Floor, Properties.Resources.Floors);

           MyMenuItem rooms = GetMenuItem(BuildingPartType.Room, Properties.Resources.Rooms);

           MyMenuItem corridors = GetMenuItem(BuildingPartType.Corridor, Properties.Resources.Corridors);

           MyMenuItem cabinets = GetMenuItem(BuildingPartType.Cabinet, Properties.Resources.Cabinets);

          //seperator = new MySeparator();

          // MyMenuItem subtrade = GetMenuItem(typeof (ITrade), Properties.Resources.Subtrade);

          MySeparator seperator = new MySeparator();

           MyMenuItem devices = GetMenuItem(typeof (IDevice), Properties.Resources.Devices + " ...");
          collectionWasSet = true;
          switch (buildingPart.Type)






Dec 16, 2009 at 4:29 PM

I'm not sure it will help you, but I access menus this way:

Dec 17, 2009 at 9:01 AM

thanks I will have a look for it