private void RebuildMenu(LinkGroupCollection groups) { this.groupMap.Clear(); if (groups != null) { // fill the group map based on group key foreach (var group in groups) { var groupKey = GetGroupKey(group); ReadOnlyLinkGroupCollection groupCollection; if (!this.groupMap.TryGetValue(groupKey, out groupCollection)) { // create a new collection for this group key groupCollection = new ReadOnlyLinkGroupCollection(new LinkGroupCollection()); this.groupMap.Add(groupKey, groupCollection); } // add the group groupCollection.List.Add(group); } } // update current selection UpdateSelection(); }
private void UpdateSelection() { LinkGroup selectedGroup = null; Link selectedLink = null; Uri sourceNoFragment = NavigationHelper.RemoveFragment(this.SelectedSource); if (this.LinkGroups != null) { // find the current select group and link based on the selected source var linkInfo = (from g in this.LinkGroups from l in g.Links where l.Source == sourceNoFragment select new { Group = g, Link = l }).FirstOrDefault(); if (linkInfo != null) { selectedGroup = linkInfo.Group; selectedLink = linkInfo.Link; } else { // could not find link and group based on selected source, fall back to selected link group selectedGroup = this.SelectedLinkGroup; // if selected group doesn't exist in available groups, select first group if (!this.LinkGroups.Any(g => g == selectedGroup)) { selectedGroup = this.LinkGroups.FirstOrDefault(); } } } ReadOnlyLinkGroupCollection groups = null; if (selectedGroup != null) { // ensure group itself maintains the selected link selectedGroup.SelectedLink = selectedLink; // find the collection this group belongs to var groupKey = GetGroupKey(selectedGroup); this.groupMap.TryGetValue(groupKey, out groups); } this.isSelecting = true; // update selection SetValue(VisibleLinkGroupsPropertyKey, groups); SetCurrentValue(SelectedLinkGroupProperty, selectedGroup); SetCurrentValue(SelectedLinkProperty, selectedLink); this.isSelecting = false; }