0

I didn't find an answer about what i'm trying to do

I'm launching my app via a custom url (like "myurl://...) and I'd like to get the parameters

My app is called via an url that looks like this :

myurl://authentication?login=foo&options=bar&returnurl=http%3A%2F%2Fwww.foobarbaz.com

When it is called, a class called AssociationUriMapper tells which page should load depending on the url (if it contains authentication or something else), and then the page loads. This page is functionnal but my problem is that i need to get the url parameters like the login, the options, and the return url. So my problem is, how do I transmit these parameters ? Or at least, how do i transmit the entire URL ? (I have my own url parser to get the parameters)

What I want to do is, when i say to my AssociationUriMapper which page it should call, I want it to transmit the url to the page's behind code. In my AssociationUriMapper class the code is :

if (tempUri.Contains("myurl"))
        {
            string urlCalledType;
            urlCalledType = "";
            if (tempUri.Contains("authentication"))
                urlCalledType = "authentication";
            if (tempUri.Contains("foo"))
                urlCalledType = "foo";

            switch (urlCalledType)
            {
                case "authentication":
                    return new Uri("/Views/AuthenticationView.xaml", UriKind.Relative);
                case "foo":
                    return new Uri("/Views/FooView.xaml", UriKind.Relative);
                default:
                    return new Uri("/MainPage.xaml", UriKind.Relative);

            }
        }

I know my code isn't very optimized but this is not really relevant for now, it's a test app and not the final app that I will be releasing

So what should I add and where, so that when I go to the AuthenticationView.xaml, the url that made the app open is transmitted to the AuthenticationView.xaml.cs ?

I hope my question is clear enough to be understood, and thanks to whoever can help !

DevBob
  • 835
  • 2
  • 9
  • 29

1 Answers1

1

You can either do this in your AuthenticationView.xaml.cs (if that is the page you are landing on when your app opens).

The login is the same for multiple parameters.

protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
    base.OnNavigatedTo(e);   
    string parameterValue = NavigationContext.QueryString["parameter"];   
}

or this:

protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
    base.OnNavigatedTo(e);   
    string parameter = string.Empty;
    if (NavigationContext.QueryString.TryGetValue("parameter", out parameter))
    {
        //do something with the parameter
    }
}
meneses.pt
  • 2,588
  • 3
  • 27
  • 38
  • 1
    Yes, I was just looking at a link that explained how to do it like the first way you suggested. For other people that might seek the answer to this question, the "parameter" has to be passed this way in your AssociationURIMapper class : return new Uri("/Views/FooView.xaml?parameter=bar", UriKind.Relative); – DevBob May 26 '14 at 15:26