Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 781271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T20:12:24+00:00 2026-05-14T20:12:24+00:00

I have a Menu and Submenu structure in Silverlight, and I want the submenu

  • 0

I have a Menu and Submenu structure in Silverlight, and I want the submenu to disappear when the parent menu item loses focus – standard Menu behavior. I’ve noticed that the submenu’s click events are lost when a submenu item is clicked, because the parent menu item loses focus and the submenu disappears.

It’s easier to explain with code:

        ParentMenuBtn.Click += delegate
        {
            SubMenu.Visibility = (SubMenu.Visibility == Visibility.Visible) ? SubMenu.Collapsed : SubMenu.Visible;
        };
        ParentMenuBtn.LostFocus += delegate
        {
            SubMenu.Visibility = Visibility.Collapsed;
        };
        SubMenuBtn.Click += delegate
        {
            throw new Exception("This will never be thrown.");
        };

In my example, when SubMenuBtn is clicked, the first event that triggers is ParentMenuBtn.LostFocus(), which hides the container of SubMenuBtn. Once the container’s visibility collapses, the Click event is never triggered.

I’d rather avoid having to hide the sub-menu each time, but I’m a little surprised that the Click event is never triggered as a result…

I can’t put any checks inside the LostFocus() event to see if my SubMenuBtn has focus, because it does not gain focus until after the LostFocus() event is called. In other words, SubMenuBtn.IsFocused = false when LostFocus() is triggered.

Anyone have any thoughts about this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T20:12:24+00:00Added an answer on May 14, 2026 at 8:12 pm

    I’ve found out the solution – albeit, it’s not as simple, or elegant as I would have liked. The solution is to use a secondary thread that pauses only for a moment before executing.

    ie.

    public partial class Navigation : UserControl
    {
        public Navigation()
        {
            ParentMenuBtn.Click += delegate
            {
                SubMenu.Visibility = (SubMenu.Visibility == Visibility.Visible) ? Visibility.Collapsed : Visibility.Visible;    
            };
            ParentMenuBtn.LostFocus += delegate(object sender, RoutedEventArgs e)
            {
                HideSubMenu(SubMenu);
            };
            SubMenuBtn.Click += delegate
            {
                //Sub Menu Button actions...
            };
    
        private void HideSubMenu(UIElement subMenu)
        {
            //Get the Main Page
            App app = (App)Application.Current;
            MainPage mainPage = (MainPage)app.RootVisual;
    
            Thread thread = new Thread(Navigation.HideSubMenu);
            thread.Start(new ThreadState(mainPage, subMenu));
        }
    
        private static void HideSubMenu(object threadStateObj)
        {
            ThreadState threadState = (ThreadState)threadStateObj;
            //Execute after 5 milliseconds...
            System.Threading.Thread.Sleep(5);
            threadState.MainPage.Dispatcher.BeginInvoke(delegate() {
               threadState.TargetElement.Visibility = Visibility.Collapsed;
            });
        }
    

    I just use a simple object called ThreadState to handle all the state objects I want to preserve:

    public class ThreadState
    {
        public MainPage MainPage = null;
        public UIElement TargetElement = null;
    
        public ThreadState(MainPage mainPage, UIElement targetElement)
        {
            this.MainPage = mainPage;
            this.TargetElement = targetElement;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the menu structure like below, <div class=submenu> <ul class=treeview> <li class=submenu id=menu-item-5592
I have menu structure as show here . All item have a background img.
i have ul li structure like below <ul class=lft_mnu id=menu-main-menu> <li class=menu-item menu-item-type-post_type menu-item-object-page
I have a menu structure (Drupal) that contains elements representing a menu link. If
i have following menu structure and using the standard menu joomla module: menu top
I have menu structure like below, <ul class=sub-menu> <li class=menu-item menu-item-type-post_type menu-item-object-page menu-item-34 id=menu-item-34><a
suppose we have a menu that two of the items contain a submenu ,
I have a menu item that appears when right clicking over a datagridview. From
I have a menu with submenus that can be toggled (hide/show type deal). Is
I have a dropdown (ul.sub-menu) with items inside (ul.sub-menu > li) that I'd like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.