Esempio n. 1
0
        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;
        }
Esempio n. 2
0
 /// <summary>
 /// Gets a non-null key for given group.
 /// </summary>
 /// <param name="group"></param>
 /// <returns></returns>
 private static string GetGroupKey(LinkGroup group)
 {
     // use special key for GroupKey <null>
     return(group.GroupKey ?? "<null>");
 }