public void RegisterGroup(object groupIdentifier, IEnumerable <AppBarIconButton> iconButtons = null, IEnumerable <AppBarMenuItem> menuItems = null, Action <AppBarGroup> initializer = null) { var group = new AppBarGroup(groupIdentifier, iconButtons, menuItems); if (initializer != null) { initializer(group); } RegisterGroup(group); }
public void RegisterGroup(AppBarGroup group) { _groups.Add(group); foreach (AppBarIconButton iconButton in group.IconButtons) { string imageUrl = iconButton.RelativeUrl.ToString(); if (!string.IsNullOrWhiteSpace(imageUrl)) { iconButton.RelativeUrl = new Uri(_imagesRootFolder + imageUrl); } } }
public void Update(object groupIdentifier) { if (groupIdentifier == null) { throw new ArgumentNullException("groupIdentifier"); } _applicationBar.Buttons.Clear(); _applicationBar.MenuItems.Clear(); AppBarGroup matchingGroup = _groups.FirstOrDefault(group => group.GroupIdentifier.Equals(groupIdentifier)); if (matchingGroup == null) { throw new ArgumentException( string.Format("Group identifier {0} could not be found in the registered groups", groupIdentifier), "groupIdentifier"); } bool hasNoItems = matchingGroup.IconButtons.Count == 0 && matchingGroup.MenuItems.Count == 0; _applicationBar.IsVisible = !hasNoItems; if (hasNoItems) { return; } bool hasOnlyMenuItems = matchingGroup.IconButtons.Count == 0; if (hasOnlyMenuItems && !matchingGroup.Mode.HasValue) { _applicationBar.Mode = ApplicationBarMode.Minimized; } else { _applicationBar.Mode = matchingGroup.Mode.GetValueOrDefault(ApplicationBarMode.Default); } foreach (AppBarIconButton iconButton in matchingGroup.IconButtons) { var button = new ApplicationBarIconButton(iconButton.RelativeUrl); button.Text = iconButton.Text; button.Click += iconButton.ClickHandler; _applicationBar.Buttons.Add(button); } if (matchingGroup.MenuItems.Count > 0) { _applicationBar.IsMenuEnabled = true; foreach (AppBarMenuItem menuItem in matchingGroup.MenuItems) { var item = new ApplicationBarMenuItem(menuItem.Text); item.Click += menuItem.ClickHandler; _applicationBar.MenuItems.Add(item); } } else { _applicationBar.IsMenuEnabled = false; } _applicationBar.Opacity = matchingGroup.Opacity; if (matchingGroup.OnActivated != null) { matchingGroup.OnActivated(matchingGroup.GroupIdentifier); } }