WPF Menu Problem

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

Hi

 

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.

2.

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 :(

Coordinator
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)

http://yfrog.com/10splitbuttonj

 

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);
          //collection.Add(trade);

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

          //MySeparator seperator = new MySeparator();
          //collection.Add(seperator);

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

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

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

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

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

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

          //seperator = new MySeparator();
          //collection.Add(seperator);

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

          MySeparator seperator = new MySeparator();
          collection.Add(seperator);

           MyMenuItem devices = GetMenuItem(typeof (IDevice), Properties.Resources.Devices + " ...");
          collection.Add(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:

http://natooktesting.wordpress.com/2009/12/16/howto-do-basic-things-using-projectwhitewhite/

Dec 17, 2009 at 9:01 AM

thanks I will have a look for it