none
How to get not null AdornerLayer for MenuItem before expanding the menu RRS feed

  • Question

  • Following code snippet gives me null adornerLayer

      Menu menu = (Menu)this.FindName("Menu");
      MenuItem menuItem = (MenuItem) menu.Items.GetItemAt(0);

      MenuItem subMenuItem = (MenuItem) menuItem.Items.GetItemAt(1);

      var layer = AdornerLayer.GetAdornerLayer(subMenuItem);
      layer.Add(new SimpleCircleAdorner(subMenuItem));

    In case that I'll add line:

      menuItem.IsSubmenuOpen = true

    Menu is expanded programatically and the adorner layer is not null.
    Is there a possibility to get not-null adorner for not expanded menu? (for first time)
    Edit1: Ok, it seems that visual tree is not created before menu-open. I'm still not sure how to trigger creation of visual tree programmatically.



    • Edited by tomas666 Friday, July 26, 2019 7:17 PM
    Friday, July 26, 2019 7:17 PM

All replies

  • Hi tomas666,

    Thank you for posting here.

    According to your description, I have a question to confirm with you.

    What's the type of your application? Winform? WPF?

    Please provide more information, and this will help us quickly analyze your problem.

    We are waiting for your update.

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, July 29, 2019 5:53 AM
    Moderator