Andrej
Andrej

Reputation: 991

Silverlight 3 Navigation Framework: Query Custom URLs

It seems that with the Silverlight 3 Navigation Framework, it is possible to get a PHP-like parameter query mechanism like so:

mydomain.com/Views/News.xaml?title=SomeTitle

..and get the title via Code-Behind.

But what I want is something like this:

mydomain.com/Views/SomeCustomText

I need to access "SomeCustomText" (or any custom value after /Views/ for that matter) in Code-Behind. Is this possible?

Thanks, Andrej

Upvotes: 0

Views: 363

Answers (1)

pho79
pho79

Reputation: 1785

Yes, if I understand your question, it's possible. I'd recommend something like the following in the frame:

<uriMapper:UriMapping Uri="/Views/{myVar}" MappedUri="/Views/Main.xaml?myVar={myVar}"/>

then, in Main.xaml.cs, you should be able to do the following:

  this.Loaded += Main_Loaded;
   ...
  public void Main_Loaded(object sender, RoutedEventArgs e)
  {
    if (this.NavigationContext.QueryString.ContainsKey("myVar"))
      var v = this.NavigationContext.QueryString["myVar"];
      //v will be "SomeCustomText" if you went to mydomain.com/Views/SomeCustomText
  }

Upvotes: 1

Related Questions