HierarchicalDataTemplate with Menu Item

Hello 
I have a ObservableCollection with properties: Name, Age, State, City.
I would like to display the States in Item menu Control, which will have City as child  and Citiy will have Name as Chlid too.
something like this.
Menu
State1 -> City1
State2      City2 ->   Name1
                 City3        Name2
I tried to follow this tutorial but I blocks.
https://zamjad.wordpress.com/2009/12/18/using-hierarchical-data-template-with-menu-item/
His example works but rather to define the value in the Window1 (), I would like to link value directly to my collection .
And also I have difficulty in using the HierarchicalDataTemplate on 3 level.
Can you help me?
Thanks in advance

>>I would like to display the States in Item menu Control, which will have City as child  and Citiy will have Name as Chlid too.
Then you should create three different classes:
namespace WpfApplication1
public class State
public string Name { get; set; }
public List<City> Cities { get; set; }
public class City
public string Name { get; set; }
public List<Name> Names { get; set; }
public class Name
public string FName { get; set; }
public string LName { get; set; }
..and set the ItemsSource of the Menu to a colletion of State objects that are populated with the corresponding cities and names as per the above structure, i.e. you will have to create a new collection of State objects from your existing (type = Name, Age,
State, City) collection to begin with.
You can then define the appearance of each type above using DataTemplates. Something like this:
<Menu xmlns:local="clr-namespace:WpfApplication1">
<Menu.Resources>
<HierarchicalDataTemplate DataType="{x:Type local:State}"
ItemsSource = "{Binding Path=Cities}">
<TextBlock Text="{Binding Path=Name}"/>
</HierarchicalDataTemplate>
<HierarchicalDataTemplate DataType="{x:Type local:City}"
ItemsSource = "{Binding Path=Names}">
<TextBlock Text="{Binding Path=Name}"/>
</HierarchicalDataTemplate>
<DataTemplate DataType="{x:Type local:Name}">
<TextBlock Text="{Binding Path=Name}"/>
</DataTemplate>
</Menu.Resources>
</Menu>
Hope that helps.
Please remember to close your threads by marking helpful posts as answer and please start a new thread if you have a new question.

Similar Messages

  • Mouse state with menu items overlapping control

    Hi,
    I have an issue with retrieving the mouse location using GetGraphCoordsFromPoint...
    I am using the return status of GetGraphCoordsFromPoint to determine if the mouse cursor is above the plot area of my graph control (1) or not (0) in order to switch between the mouse styles (VAL_DEFAULT_CURSOR versus VAL_CROSS_HAIR_CURSOR).
    It works in most cases...
    On top of the panel there is a menu bar, located below is the xy graph. Now, if the mouse opens a menu and is over the menu (and also over the graph) the mouse style depends on mouse history:
    If the mouse has always been located over the menu, it is not recognized by GetGraphCoordsFromPoint to be loacted over the graph - which is what I would like to see, in this case the cursor style still is the default style.
    Now, if the mouse leaves the menu for a short distance, the menu does not disappear (only if the mouse is at a larger distance) and acccordingly GetGraphCoordsFromPoint realizes that the mouse is over the graph. This is correct and as expected, too.(the mouse style is changed to a cross hair then)
    Now, if I move the mouse back over the menu, this is not recognized by GetGraphCoordsFromPoint, unfortunately, and the mouse style is not switched back to default.
    Am I missing something, or is there a way to correct this behavior? Having different mouse styles over a menu is confusing for the user and I'd like to avoid that, of course
    Thanks....
    Solved!
    Go to Solution.

    Hi Wolfgang,
    There isn't a very good way to get around this problem. As you've found, panel move events are sent to the panel's callback even while a menu is being tracked, and when you change the mouse cursor this this also impacts any menu that might be active at the time.
    If you don't mind the cursor not changing at all while the menu is active, even if the user moves over the graph, then there is a possible strategy you can pursue to remedy the situation. It consists of trying to detect when a menu is active so that you don't try to change the cursor while the menu is active. Unfortunately, this is easier said than done. Although it's straightforward to be notified whenever a new menu becomes active (via a menu dimmer callback) there is no good way to be notified when the menu goes away. And there are multiple ways in which it can go away. So it it not possible for you to set an internal flag that tracks when the menu is active.
    However, it is possible to find out whether the menu is active at the time that you receive the panel move event (or in the timer tick event, although I'm not completely sure why you are also using a timer). You can't do it with the CVI UI library, but you can, using the Windows SDK, in a somewhat round-about way.
    The idea is to find out which window is the topmost window. And if it is not the panel window, then you should be able to assume that a menu is active and thus refrain from changing the cursor. Note that you also have to make sure that the active window belongs to your process, since there could be any number of other windows that could be the "topmost" window at any one time. But if it belongs to your process and it is not your panel, then we can assume that it's the menu.
    I did a quick test with the following code and it seems to work, although you might want to test it more thoroughly than I did:
    topHwnd = GetTopWindow (NULL);
    GetWindowModuleFileName (topHwnd, topHwndModule, MAX_PATHNAME_LEN);
    GetPanelAttribute (panel, ATTR_SYSTEM_WINDOW_HANDLE, (intptr_t *)&panelHwnd);
    GetWindowModuleFileName (panelHwnd, panelHwndModule, MAX_PATHNAME_LEN);
    if (!strcmp (topHwndModule, panelHwndModule) && panelHwnd != topHwnd)
        return 0; // don't change the cursor unless the panel really is on top
    Good luck,
    Luis

  • Muse crashes with menu item box has no associated page

    My file is crashing when I click on the menu in Master page with a menu error "menu itembox 07012 has no associated page.  Also crashes when I try to add or delete a page anywhere. I believe this started after I deleted a page. The page deleted, but the menu retained the pulldown link. Any thoughts on how I can resolve this?

    I had the same problem today after deleting a page. I posted a question here and saw your problem.
    A little later I decided to delete my main menu and then install a new identical menu. That solved the problem.
    Good luck.
    Paul

  • Duplications in "Open With" menu

    Sometimes after I upgrade an application, the "Open with" menu item in the Finder lists this application twice. Curiously, it doesn't list the duplication in all accounts. Is there any way I can remove the duplicates?

    Esaheiskanen, looking at the screenshot, I understand that it was removed properly.
    You can simply go to >>>> Go> Utilites> Adobe Installer's and remove the CS6 App installed, Make sure you put a check on "Remove Prefrences" too.
    Alternatively, you run the Creative Cloud Cleaner Tool, to remove the CS6 Version.
    Cheers
    LP

  • Forms 9i Menu Item Open_form

    I have been using Forms 6 by creating a menu with menu item that can call the logical name of form without giving the full path and filename.
    e.g. open_form('maintain_dept');
    as well as
    open_form('c:\dev_r6\maintain_dept.fmx');
    I found that Forms 9i dos not support calling form by logical form name, i.e. open_form('maintain_dept');
    will not work, but
    open_form('c:\dev_r6\maintain_dept.fmx');
    works well. Can anyone tell me how to call form without specifying the full path and filename?

    You simply need the form's FMX to be in your FORMS90_PATH variable. This is set up in the default.env file on your Forms server machine.

  • Adjusting margins between horizontal menu items

    I noticed you can adjust the padding with menu items, but not the margins?  Is there a way to adjust the margins between each menu item ?

    In that case you will need to use images.
    <!DOCTYPE HTML>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>Untitled</title>
    <script src="SpryAssets/SpryMenuBar.js" type="text/javascript"></script>
    <link href="SpryAssets/SpryMenuBarHorizontal.css" rel="stylesheet" type="text/css">
    <style>
    ul.MenuBarHorizontal a.line {    background: #EEE url(SpryMenuBarLine.gif) no-repeat 95% 50%; }
    ul.MenuBarHorizontal a.MenuBarItemSubmenu.line{    background: #EEE url(SpryMenuBarDownLine.gif) no-repeat 95% 50%; }
    </style>
    </head>
    <body>
    <ul id="MenuBar1" class="MenuBarHorizontal">
      <li><a class="MenuBarItemSubmenu line" href="#">Item 1</a>
        <ul>
          <li><a href="#">Item 1.1</a></li>
          <li><a href="#">Item 1.2</a></li>
          <li><a href="#">Item 1.3</a></li>
        </ul>
      </li>
      <li><a href="#" class="line">Item 2</a></li>
      <li><a class="MenuBarItemSubmenu line" href="#">Item 3</a>
        <ul>
          <li><a class="MenuBarItemSubmenu" href="#">Item 3.1</a>
            <ul>
              <li><a href="#">Item 3.1.1</a></li>
              <li><a href="#">Item 3.1.2</a></li>
            </ul>
          </li>
          <li><a href="#">Item 3.2</a></li>
          <li><a href="#">Item 3.3</a></li>
        </ul>
      </li>
      <li><a href="#">Item 4</a></li>
    </ul>
    <script type="text/javascript">
    var MenuBar1 = new Spry.Widget.MenuBar("MenuBar1", {imgDown:"SpryAssets/SpryMenuBarDownHover.gif", imgRight:"SpryAssets/SpryMenuBarRightHover.gif"});
    </script>
    </body>
    </html>
    The images look similar to the following
    and
    I hope this helps.
    Ben

  • How do I create a drop down menu with multiple items in Adobe Acrobat 9?

    I am trying to create a drop down menu with four items within a field box.  When I try to do this
    the font is too big and it just doesn't fit.

    You can use panel widget to create manual menu where set to show target on rollover.
    Something like this :
    http://muse.adobe.com/exchange-library/menu-vertical-accordion-widget-1
    http://muse.adobe.com/exchange-library/tiptop-navigation-menu
    Thanks,
    Sanjit

  • How do I change stills with each menu item selected?

    Hi all.
    I am trying to create a menu (with 10 items) which contains one single dropzone box, which will contain a still that changes with each menu item selected (instead of 10 different stills next to each item).
    I have absolutely no idea how to achieve this! Do I create a different menu for each item? Is there a way to have a slideshow within the menu that changes with each item selected?
    Please help!
    Many thanks
    James

    THe way to do what you want to do is layered menus which have some limits
    http://dvdstepbystep.com/layersover.php
    What you would do is change the item that appears in the same section - in other words there would be ten layers with a diffrerent picture in the same exact spot, the rectangle buttons sections do not need to be over the picture section
    http://dvdstepbystep.com/Layers_Example.dmg is a project that does changing images.

  • Removing Items Finder Open With Menu

    I'm looking for a way to delete items from the Open With menu in Finder/File/Open With. On my PowerBook there are over fifty items in this menu when selecting a JPEG file.
    Maybe there is away.
    I'm using a Panther drive 10.3.9
    Photoscene

    Photoscene-
    I'm not sure this addresses your exact situation or not, but the following link:
    http://www.macosxhints.com/article.php?story=20031215144430486#comments
    suggests a method for removing items from the "open with" menu that shouldn't be there.
    I have NOT tried the above, so use the usual cautions (backup beforehand, etc.).
    Good luck,
    Alan
    cube   Mac OS X (10.3.9)  

  • Lost most of the Apple Menu items with 10.8.5

    I have only
    About This Mac
    Force Quit...
    Sleep
    Log Out (User)...
    The Finder starts up as Simple Finder, I have to select Run Full FInder to get the full Finder back but it does not reactivate the Apple Menu items.
    After restarting the computer the Finder again opens as Simple Finder.
    Root has access to the normal Apple Menu items.
    Please someone give me some advice
    Thanks

    Part of your problem, at least, is that you're in single-application mode.
    Back up all data.
    I've tested these instructions only with the Safari web browser. If you use another browser, they may not work as described.
    Triple-click anywhere in the line below on this page to select it:
    defaults delete com.apple.dock single-app && killall Dock
    Copy the selected text to the Clipboard (command-C).
    Launch the Terminal application in any of the following ways:
    ☞ Enter the first few letters of its name into a Spotlight search. Select it in the results (it should be at the top.)
    ☞ In the Finder, select Go ▹ Utilities from the menu bar, or press the key combination shift-command-U. The application is in the folder that opens.
    ☞ Open LaunchPad. Click Utilities, then Terminal in the icon grid.
    Paste into the Terminal window (command-V). You should get a new line ending in a dollar sign ("$"). You can then quit Terminal. Test.

  • Help. Need to remove item from the "open with" menu

    Does anyone know how I can remove an item from the "open with" menu?

    You could try removing the quicktime .pkg files from the receipts folder in the root library.
    The system has to go somewhere to determine eligible applications it can use to open a file.
    Each application would contain its base settings in its receipts file.
    Once you delete the receipt you should delete the application and reinstall it.
    The reinstall will write a new receipts file.
    The receipts file is used by your system when it repairs disk permissions.
    The system does not just add a setting.
    For example if you take a .png file and click on it and look at what can open it you may get a long list.
    If you choose "other" from the get info "open with" menu and have acrobat reader installed in applications, it will show as an application you can choose.
    That application, however, is not in the drop down list.
    If you choose acrobat reader and apply it to the file type, it will show as the default.
    If you then choose another application in the list and apply, Acrobat Reader disappears from the list.
    The system only shows files in the list that advertise to the system that they can read the file type.
    You have a system which is populating the list with legitimate programs that are compatible with the advertised file type.
    It is reading that advertisement for the quicktime application somewhere.
    The configuration is written to each file individually, you can choose to have a single file associated with a particular application or have it apply to all files of that type.
    Check in Spotlight for a copy of the application in another location.

  • Two "Adobe Reader" menu items in "Open with" context menu

    Is there a simple remedy to the problem of multiple occurrences of "Adobe Reader" in the context menu?
    That is, in the Finder, on Mac OS 10.6.8, I see two instances of "Adobe Reader" in the "Open with..." context menu...
    thank you in advance.

    Hi!
    thanks for the response! I would be happy to find the root cause of this issue (or at least find and remove the data in the facility called Launch Services.
    I have no additional binaries of Adobe Reader on the disk. One only.
    I think there is some crufty data somewhere, which Launch Services is reading and hence displaying the erroneous menu item.
    I suspect the Adobe Reader installer is somehow responsible for this. This was a clean and newly built system disk. 
    I have been reading the following:
    How to rebuild the LaunchServices database
    Launch Services Framework Release Notes for Mac OS X v10.5
    Rebuild Launch Services Database
    Now, I tried resetting the "global Launch Services database".
    I must restart Finder to see if this was successful. Until later...

  • Remove double items (programs) from Open With menu??

    Hello;
    Since some disk perturbances and hooking up an external HD for backup there is one notorious issue in my Finder (Panther 10.3.9): All the applications are listed twice, overstuffing the right-click menu with double Safaris, double Previews and so on.
    How do I get rid of this stuff? My Contextual Menu items' removal makes no difference (I have just two), as well as trashing the Finder preferences. Do I have any influence on how this list is being built?
    I've searched Apple tech articles and this forum, to no avail. Somebody knows the solution? This is very annoying...
    PowerBook G4 Alu 1.25GHz   Mac OS X (10.3.9)  

    Try these:
    1) Repair permissions using Disk Utility (Applications >> Utilities)
    2) Repair Disk (Bootup from OS X Install Disk 1)
    3) Clean System and User caches
    4) Optimize the System
    5) Update "whatis Mac OS X" database
    Everything here except Repairing the Disk can be done with the freeware utility "OnyX" (www.titanium.free.fr). In OnyX, Tasks 1, 4, and 5 and be found in the "Maintenance" tab. Task 3 is found in the "Cleaning" tab. More in-depth info about these tasks can be found at my System Maintenance and General Troubleshooting guides:
    System Maintenance: http://happymac.50webs.com/smx.html
    General Troubleshooting: http://happymac.50webs.com/gtx.html
    Indragie

  • Remove Items from "Open With" Menu

    I installed Photoshop CS2 last week and it added a ton of unnecessary and unwanted items in the "Open With" menu in Tiger...
    Sorry that image is so large, but imagine having to look at that on a regular basis. Can I remove all of that crap?! It's slowed Tiger's performance considerably.

    If you are never going to use them, you can simply trash and restart. Or you can do what I (and many others) have done and leave the ones you do use and zip the rest. They are here:
    "/Applications/Adobe Photoshop CS/Samples/Droplets"
    There's one folder for Photoshop, and second for ImageReady.
    Francine
    Francine
    Schwieder

  • How do you edit photos with photoshop from the new  Photos app?  The edit in external editor menu item seems to be gone.

    How do you edit photos with photoshop from the new  Photos app?  The edit in external editor menu item seems to be gone.

    Tell Apple what additional features you want in Photos via both http://www.apple.com/feedback/macosx.html and http://www.apple.com/feedback/iphoto.html  since they don't have a feedback page for Photos as yet.

Maybe you are looking for