This project is read-only.

Selected Link Group when using Query strings

May 3, 2013 at 3:09 PM
Edited May 3, 2013 at 3:13 PM
I ran into a problem with the link group not being selected when a query string was present in the Path.

For example: /Path/MyPage.xaml?id=4

I wanted to pass a parameter to the page, but when there was a parameter the tab wasn't being selected. Not sure if I did this correctly but what I did was modify the UpdateSelected() Function in ModernMenu.cs. Figured I would share my changes
private void UpdateSelection()
        {
            LinkGroup selectedGroup = null;
            Link selectedLink = null;

            if (this.LinkGroups != null) {
                // find the current select group and link based on the selected source

                Uri selected_source = this.SelectedSource;
                if (selected_source != null && selected_source.OriginalString.Contains('?'))
                {
                    // remove the query string -- can't use .Query, and other stuff on Relative Uris
                    selected_source = new Uri(string.Join(string.Empty, selected_source.ToString().Split('?').Take(1)), UriKind.RelativeOrAbsolute);
                }

                var linkInfo = (from g in this.LinkGroups
                                from l in g.Links
                                where l.Source == selected_source
                                select new {
                                    Group = g,
                                    Link = l
                                }).FirstOrDefault();
So then in the MainWindow.xaml the following will work for all /Path/MyPage.xaml calls with a query string
<mui:ModernWindow.MenuLinkGroups>
        <mui:LinkGroup DisplayName="My Page That Hosts Multiple Paramaters" GroupName="mypage">
            <mui:LinkGroup.Links>
                <mui:Link DisplayName="My Page" Source="/Path/MyPage.xaml" />
            </mui:LinkGroup.Links>
        </mui:LinkGroup>
</mui:ModernWindow.MenuLinkGroups>
Jun 24, 2013 at 10:35 PM
Edited Jun 24, 2013 at 10:35 PM
I have the exact same problem, except that I am using fragments instead of query strings.

For example, I have a:
 <mui:LinkGroup DisplayName="MyLinkGroup">
            <mui:LinkGroup.Links>
                <mui:Link DisplayName="overview" Source="/Pages/overview.xaml" />
                <mui:Link DisplayName="details" Source="/Pages/details.xaml" />
            </mui:LinkGroup.Links>
        </mui:LinkGroup>        
but then if I navigate to
new Uri(@"/Pages/details.xaml#myFragment", UriKind.Relative);
my link group "details" never gets selected. If I drop the fragment, then everything is OK.

Any ideas how to solve this without having to modify the code like above?
Jun 27, 2013 at 3:28 PM
...anyone with a suggestion on how I can navigate to a page fragment AND make sure the link in the link group is selected?
Jul 3, 2013 at 4:42 PM
Edited Jul 3, 2013 at 4:43 PM
I don't think there is much you could do other than manually setting the selected view from your codebehind in that view.

I have revisited this a few times and to fix the fragment issue I changed the .Split in the orignal post to split on '#' also. But that doesn't really answer your question
selected_source = new Uri(string.Join(string.Empty, selected_source.ToString().Split(new char[] { '?','#'}).Take(1)), UriKind.RelativeOrAbsolute);