private void BuildPimaryButtons() { int n = 0; foreach (var nuki in _settings.PairdLocks) { HamburgerButtonInfo btn = null; if (n < HamburgerMenuPrimaryButtons.Count) { btn = HamburgerMenuPrimaryButtons[n++]; } else { btn = new HamburgerButtonInfo(); HamburgerMenuPrimaryButtons.Add(btn); ++n; } btn.Visibility = Visibility.Visible; var panel = new StackPanel { Orientation = Orientation.Horizontal, }; panel.Children.Add(new SymbolIcon { Width = 48, Height = 48, Symbol = nuki.Icon }); panel.Children.Add(new TextBlock { Margin = new Thickness(12, 0, 0, 0), VerticalAlignment = VerticalAlignment.Center, Text = nuki.ConnectionName }); btn.Content = panel; btn.ClearHistory = true; btn.PageType = typeof(NukiLock); btn.PageParameter = nuki.UniqueClientID.Value; } while (n < HamburgerMenuPrimaryButtons.Count) { HamburgerMenuPrimaryButtons.RemoveAt(n); } }
private static void SetGlyphForeground(HamburgerButtonInfo info, Brush brush) { var stack = info?.Content as StackPanel; if (stack == null) { return; } var icon = stack.Children.OfType <GlyphIcon>().FirstOrDefault(); if (icon != null) { icon.Foreground = brush; } var text = stack.Children.OfType <TextBlock>().FirstOrDefault(); if (text != null) { text.Foreground = brush; } }
/// <summary> /// Returns a list of submenu buttons with the same GroupName attribute as the command button upon which this /// extension is invoked (which is treated as Parent command button). /// </summary> /// <returns>Submenu buttons in List<HamburgerButtonInfo>. If no submenu buttons found, List is still returned with element count of 0. </returns> /// <remarks> /// For added convenience, the GroupName attribute is detected with string.StartWith(groupName) rather than /// the straightforward string.Equals(groupName). That way we can tag submenu buttons as groupName1, groupName2, /// groupName3, etc. With this scheme, the parent command button should be named by subset string, /// which in this case is groupName. /// You don't have to use this scheme in which case you just stick to a single groupName for all buttons. /// </remarks> public static List <HamburgerButtonInfo> ItemsInGroup(this HamburgerButtonInfo button, bool IncludeSecondaryButtons = false) { string groupName = button.GroupName?.ToString(); // Return 0 count List rather than null if (string.IsNullOrWhiteSpace(groupName)) { return(new List <HamburgerButtonInfo>()); } FrameworkElement fe = button.Content as FrameworkElement; HamburgerMenu hamMenu = fe.FirstAncestor <HamburgerMenu>(); List <HamburgerButtonInfo> NavButtons = hamMenu.PrimaryButtons.ToList(); if (IncludeSecondaryButtons) { NavButtons.InsertRange(NavButtons.Count, hamMenu.SecondaryButtons.ToList()); } List <HamburgerButtonInfo> groupItems = NavButtons.Where(x => !x.Equals(button) && (x.GroupName?.ToString()?.StartsWith(groupName) ?? false)).ToList(); return(groupItems); }