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; //Treat same uri with different fragment as different pages //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 == this.SelectedSource //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; }
private void UpdateSelection() { LinkGroup selectedGroup = null; Link selectedLink = null; if (LinkGroups != null) { var linkInfo = (from g in LinkGroups from l in g.Links where l.Source == SelectedSource select new { Group = g, Link = l }).FirstOrDefault(); if (linkInfo != null) { selectedGroup = linkInfo.Group; selectedLink = linkInfo.Link; } else { selectedGroup = SelectedLinkGroup; if (LinkGroups.All(g => g != selectedGroup)) { selectedGroup = LinkGroups.FirstOrDefault(); } } } ReadOnlyLinkGroupCollection groups = null; if (selectedGroup != null) { selectedGroup.SelectedLink = selectedLink; var groupName = GetGroupName(selectedGroup); groupMap.TryGetValue(groupName, out groups); } isSelecting = true; SetValue(VisibleLinkGroupsPropertyKey, groups); SetCurrentValue(SelectedLinkGroupProperty, selectedGroup); SetCurrentValue(SelectedLinkProperty, selectedLink); isSelecting = false; }
private void RebuildMenu(IEnumerable <LinkGroup> groups) { groupMap.Clear(); if (groups != null) { foreach (var group in groups) { var groupName = GetGroupName(group); ReadOnlyLinkGroupCollection groupCollection; if (!groupMap.TryGetValue(groupName, out groupCollection)) { groupCollection = new ReadOnlyLinkGroupCollection(new LinkGroupCollection()); groupMap.Add(groupName, groupCollection); } groupCollection.List.Add(group); } } UpdateSelection(); }
private void RebuildMenu(LinkGroupCollection groups) { _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 (!_groupMap.TryGetValue(groupKey, out groupCollection)) { // create a new collection for this group key groupCollection = new ReadOnlyLinkGroupCollection(new LinkGroupCollection()); _groupMap.Add(groupKey, groupCollection); } // add the group groupCollection.List.Add(group); } } // update current selection UpdateSelection(); }
private void UpdateSelection() { if (!_initialized) { return; } LinkGroup selectedGroup = null; Link selectedLink = null; if (LinkGroups != null) { // find the current select group and link based on the selected source var linkInfo = (from g in LinkGroups from l in g.Links where l.Source == SelectedSource 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 = SelectedLinkGroup; // if selected group doesn’t exist in available groups, select first group if (LinkGroups.All(g => g != selectedGroup)) { selectedGroup = LinkGroups.FirstOrDefault(); } } } ReadOnlyLinkGroupCollection groups = null; if (selectedGroup != null) { // ensure group itself maintains the selected link if (selectedLink == null) { /* very questionable place */ selectedLink = selectedGroup.SelectedLink; } else { selectedGroup.SelectedLink = selectedLink; } // find the collection this group belongs to var groupKey = selectedGroup.GroupKey; _groupMap.TryGetValue(groupKey, out groups); } _isSelecting = true; // update selection SetValue(VisibleLinkGroupsPropertyKey, groups); SetCurrentValue(SelectedLinkGroupProperty, selectedGroup); SetCurrentValue(SelectedLinkProperty, selectedLink); _isSelecting = false; }