private void SelectMenuLevel3FromLevel2(ModernMenuItem selectedItem, string level3ToSelect)
        {
            ModernMenuItem selectedLevel3Item = null;

            foreach (var item3 in selectedItem.Items)
            {
                this.MainMenuLevel3.Add(item3);
                if (item3.IsSelected && level3ToSelect == null)
                {
                    selectedLevel3Item = item3;
                }
                else if (level3ToSelect == item3.Key)
                {
                    selectedLevel3Item            = item3;
                    selectedLevel3Item.IsSelected = true;
                }
                else
                {
                    item3.IsSelected = false;
                }
            }

            ItemsControl ic = this.Template.FindName("ItemsControl", this) as ItemsControl;

            ic.BeginStoryboard((Storyboard)FindResource("ContentLeftInStoryboard"));

            if (selectedLevel3Item != null)
            {
                SelectMenuItem_Level3(selectedLevel3Item);
            }
            else
            {
                SelectMenuItem_Level3(selectedItem.Items[0]);
            }
        }
        void SelectMenuItem_Level2(ModernMenuItem selectedItem, string level3ToSelect = null)
        {
            ModernMenuItem previousItem = null;

            foreach (ModernMenuItem item in selectedItem.Parent.Items)
            {
                if (item.IsSelected)
                {
                    previousItem = item;
                    break;
                }
            }
            if (LoadContent(selectedItem, out bool isLeft, out bool AnimationShown))
            {
                if (previousItem != selectedItem || (this.MainMenuLevel3.Count == 0 && selectedItem.Items != null))
                {
                    if (previousItem != null)
                    {
                        previousItem.IsSelected = false;
                    }

                    selectedItem.IsSelected = true;
                    this.MainMenuLevel3.Clear();
                    if (selectedItem.Items != null && selectedItem.Items.Count > 0)
                    {
                        SelectMenuLevel3FromLevel2(selectedItem, level3ToSelect);
                    }
                }
                else if (level3ToSelect != null && selectedItem.Items != null && selectedItem.Items.Count > 0)  //The Level2 of the KeyPath is the same, but we still need to select the 3rd level item
                {
                    SelectMenuLevel3FromLevel2(selectedItem, level3ToSelect);
                }
            }
        }
        void MainMenuItemLevel3_MouseDown(object sender, MouseEventArgs e)
        {
            ModernMenuItem item = sender as ModernMenuItem;

            if (this.Content != null && item.ContentType == this.Content?.GetType())
            {
                return;
            }
            SelectMenuItem_Level3(item);
        }
        async void MainMenuItem_MouseDown(object sender, MouseButtonEventArgs e)
        {
            ModernMenuItem item = sender as ModernMenuItem;

            if (this.Content != null && item.ContentType == this.Content?.GetType())
            {
                return;
            }
            if (!(this.Content is ModernContent currentContent) || currentContent.CanBeClosed())
            {
                suppressCanBeClosed = true;
                await SelectMenuItem_Level1(item);

                suppressCanBeClosed = false;
            }
        }
        void SelectMenuItem_Level3(ModernMenuItem selectedItem)
        {
            ModernMenuItem previousItem = null;

            foreach (ModernMenuItem item in selectedItem.Parent.Items)
            {
                if (item.IsSelected)
                {
                    previousItem = item;
                    break;
                }
            }
            if (LoadContent(selectedItem, out bool isLeft, out bool AnimationShown) && previousItem != selectedItem)
            {
                if (previousItem != null)
                {
                    previousItem.IsSelected = false;
                }
                selectedItem.IsSelected = true;
            }
        }
        async Task SelectMenuItem_Level1(ModernMenuItem selectedItem, string level2ToSelect = null, string level3ToSelect = null)
        {
            ModernMenuItem previousItem = null;

            foreach (ModernMenuItem item in this.MainMenu)
            {
                if (item.IsSelected)
                {
                    previousItem = item;
                    break;
                }
            }

            if (LoadContent(selectedItem, out bool isLeft, out bool AnimationShown))
            {
                if (previousItem != selectedItem || level2ToSelect != null)
                {
                    if (previousItem != null)
                    {
                        previousItem.IsSelected = false;
                    }

                    selectedItem.IsSelected = true;
                    this.MainMenuLevel2.Clear();
                    this.MainMenuLevel3.Clear();
                    if (selectedItem.Items != null && selectedItem.Items.Count > 0)
                    {
                        int            count = selectedItem.Items.Count;
                        ModernMenuItem selectedLevel2Item = null;
                        if (!AnimationShown)
                        {
                            HideContent(isLeft);
                        }
                        await Task.Run(() =>
                        {
                            for (int i = 0; i < count; i++)
                            {
                                this.Dispatcher.Invoke(new Action(() =>
                                {
                                    ModernMenuItem current = selectedItem.Items[i];
                                    this.MainMenuLevel2.Add(current);
                                    if (current.IsSelected && level2ToSelect == null)
                                    {
                                        selectedLevel2Item = current;
                                    }
                                    else if (level2ToSelect == current.Key)
                                    {
                                        selectedLevel2Item            = current;
                                        selectedLevel2Item.IsSelected = true;
                                    }
                                    else
                                    {
                                        current.IsSelected = false;
                                    }
                                }

                                                                  ));
                                Thread.Sleep(50);
                            }
                        }
                                       );

                        if (selectedLevel2Item != null)
                        {
                            SelectMenuItem_Level2(selectedLevel2Item, level3ToSelect);
                        }
                        else
                        {
                            SelectMenuItem_Level2(selectedItem.Items[0]);
                        }
                    }
                }
                else if (level2ToSelect != null && selectedItem.Items != null && selectedItem.Items.Count > 0)
                {
                    //The Level1 of the KeyPath is the same, so we need to select the second level item
                    int            count = selectedItem.Items.Count;
                    ModernMenuItem selectedLevel2Item = null;
                    await Task.Run(() =>
                    {
                        this.Content = null;
                        for (int i = 0; i < count; i++)
                        {
                            this.Dispatcher.Invoke(new Action(() =>
                            {
                                ModernMenuItem current = selectedItem.Items[i];
                                if (current.IsSelected && level2ToSelect == null)
                                {
                                    selectedLevel2Item = current;
                                }
                                else if (level2ToSelect == current.Key)
                                {
                                    selectedLevel2Item            = current;
                                    selectedLevel2Item.IsSelected = true;
                                }
                                else
                                {
                                    current.IsSelected = false;
                                }
                            }

                                                              ));
                            Thread.Sleep(50);
                        }
                    }
                                   );

                    if (selectedLevel2Item != null)
                    {
                        SelectMenuItem_Level2(selectedLevel2Item, level3ToSelect);
                    }
                    else
                    {
                        SelectMenuItem_Level2(selectedItem.Items[0]);
                    }
                }
            }
        }
        internal bool LoadContent(ModernMenuItem item, out bool isLeft, out bool AnimationShown)
        {
            int previousIndex, currentIndex;

            currentIndex  = item.Index;
            previousIndex = 0;
            if (recentActions.Count > 0)
            {
                ModernMenuItem previousItem = recentActions.Peek() as ModernMenuItem;
                previousIndex = previousItem.Index;
            }
            isLeft = currentIndex <= previousIndex;
            System.Diagnostics.Debug.WriteLine("IsLeft=" + isLeft);
            AnimationShown = false;
            if (item.Items != null && item.Items.Count > 0)
            {
                return(true);
            }


            if (this.Content is ModernContent currentContent && !suppressCanBeClosed && !currentContent.CanBeClosed())
            {
                return(false);
            }



            recentActions.Push(item);
            if (item.ContentType != null && item.ContentType.IsSubclassOf(typeof(ModernContent)))
            {
                Storyboard story = isLeft ? ((Storyboard)FindResource("ContentLeftInStoryboard")).Clone() : ((Storyboard)FindResource("ContentRightInStoryboard")).Clone();
                if (Cache.ContainsKey(item))
                {
                    //item has already in the Cache
                    ModernContent content = Cache[item];
                    loadedMenu = item;
                    if (LoadContentSub(content, out AnimationShown, story))
                    {
                        return(true);
                    }
                }
                else
                {
                    ModernContent content = (ModernContent)Activator.CreateInstance(item.ContentType);
                    Cache.Add(item, content);
                    loadedMenu = item;
                    if (LoadContentSub(content, out AnimationShown, story))
                    {
                        return(true);
                    }
                }
            }
            else
            {
                this.Content             = null;
                this.CommandArea         = null;
                this.IsContentDetachable = false;
                this.IsContentDetached   = false;
                loadedMenu    = item;
                nextStatusBar = DefaultStatusBar;
                if (this.StatusBar != nextStatusBar)
                {
                    if (this.StatusBar != null)
                    {
                        this.StatusBar.BeginStoryboard(HideStatusbarStoryboard);
                        System.Diagnostics.Debug.WriteLine("Hide StatueBar line 190");
                    }
                    else
                    {
                        this.StatusBar = nextStatusBar;
                        if (this.StatusBar != null)
                        {
                            this.StatusBar.BeginStoryboard(ShowStatusbarStoryboard);
                            System.Diagnostics.Debug.WriteLine("Show StatusBar line 198");
                        }
                    }
                }
            }
            return(true);
        }