Пример #1
0
        private void CalculateMenuItems(ICollection <INavigationMenuDescriptor> menuDescriptors, ICollection <SmallNavigationMenuItem> menuItems)
        {
            if (menuDescriptors == null)
            {
                return;
            }

            foreach (var menuDescriptor in menuDescriptors)
            {
                var menuItem = new SmallNavigationMenuItem {
                    DataContext = menuDescriptor
                };
                menuItem.SetBinding(SmallNavigationMenuItem.ItemTemplateProperty, new Binding(menuDescriptor.IsRoot ? "RootItemTemplate" : "LeafItemTemplate")
                {
                    Source = this
                });
                menuItem.AddHandler(SmallNavigationMenuItem.SelectionChangedEvent, new RoutedPropertyChangedEventHandler <bool>(OnSmallNavigationMenuItemSelectionChanged));
                menuItems.Add(menuItem);

                if (!(menuDescriptor.Items?.Any() ?? false))
                {
                    continue;
                }

                if (menuItem.MenuItems == null)
                {
                    menuItem.MenuItems = new List <SmallNavigationMenuItem>();
                }

                CalculateMenuItems(menuDescriptor.Items, menuItem.MenuItems);
            }
        }
Пример #2
0
        private void UnselectOldSelectedMenuItems(SmallNavigationMenuItem selectedMenuItem)
        {
            var oldSelectedMenuItems = MenuItems.Where(item => item.MenuItems != null)
                                       .SelectMany(item => item.MenuItems)
                                       .Concat(MenuItems)
                                       .Where(item => !Equals(item, selectedMenuItem))
                                       .Where(item => item.IsSelected)
                                       .ToArray();

            foreach (var item in oldSelectedMenuItems)
            {
                item.ClosePopup();

                if (item.MenuItems?.All(x => !Equals(x, selectedMenuItem)) ?? true)
                {
                    item.IsSelected = false;
                }
            }
        }
Пример #3
0
 private void SelectMenuItem(SmallNavigationMenuItem item)
 {
     SelectedItem     = item.DataContext as INavigationMenuDescriptor;
     SelectedMenuItem = item;
     UnselectOldSelectedMenuItems(item);
 }