示例#1
0
        private void UpdateSelection()
        {
            LinkGroup selectedGroup = null;
            Link      selectedLink  = null;

            Uri sourceNoFragment = NavigationHelper.RemoveFragment(SelectedSource);

            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 == 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 = SelectedLinkGroup;

                    // if selected group doesn't exist in available groups, select first group
                    if (!LinkGroups.Any(g => g == selectedGroup))
                    {
                        selectedGroup = 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
                string groupKey = GetGroupKey(selectedGroup);
                groupMap.TryGetValue(groupKey, out groups);
            }

            isSelecting = true;
            // update selection
            SetValue(VisibleLinkGroupsPropertyKey, groups);
            SetCurrentValue(SelectedLinkGroupProperty, selectedGroup);
            SetCurrentValue(SelectedLinkProperty, selectedLink);
            isSelecting = false;
        }
示例#2
0
        private bool SelectUriIfLinkExists(Uri uri)
        {
            if (uri != null)
            {
                RaiseEvent(new InitializeEventArgs(InitializeEvent, uri));
                var selected = LinkGroups.SelectMany(g => g.Links).FirstOrDefault(t => t.Source?.ToString() == uri.ToString());
                if (selected != null)
                {
                    SelectedLink = selected;
                    return(true);
                }
            }

            return(false);
        }
示例#3
0
        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;
        }
示例#4
0
        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;
        }