1

Given a PhoneApplicationPage sub type, is there a way (other than relying on convention) to figure out its internal uri?

In other words, I want to call GetUri<MyPage>() and get back something like /Views/MyPage.xaml.

Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72
ehnmark
  • 2,656
  • 3
  • 24
  • 20
  • Of course if you have more than 1 page of each type then this scheme won't work anyway, unless you get a collection of pages back. Does UriMapper do what you need - [see link here](http://www.silverlightshow.net/items/The-Silverlight-3-Navigation-Framework.aspx)? – Paul Annetts Jul 20 '11 at 13:12
  • How can a single page type have more than one uri (ignoring the query string)? – ehnmark Jul 20 '11 at 13:23
  • Good point... Too much looking at DI frameworks and object scopes recently. – Paul Annetts Jul 20 '11 at 13:37

3 Answers3

1

There is no way to do this. There is no meta data that points relates a XAML file name to a type. The filename is essentially the key by which the runtime identifies the BAML to load and it's from that BAML that it knows the type. Going the other direction would be very difficult.

Short of reading the BAML resource streams and figuring out the mapping yourself (which can't easily be done in Silverlight and would kill performance even if it could) I can't see a way of doing this.

1adam12
  • 985
  • 5
  • 13
0

Will it be possible to do something similar to this:

C# Silverlight 3 - Programmatically Navigate Between Pages?

Where he is defining navigation mappings. I'll be trying this tonight in my app, I currently just maintain a static dictionary of page types against their URI; unfortunately this is all manual.

Community
  • 1
  • 1
Adam Houldsworth
  • 63,413
  • 11
  • 150
  • 187
  • UriMapper still requires me to tell Silverlight what the uri to each page is. I'm hoping to be able to refer to my pages by type only when doing navigation, so that I can move stuff around without having to update mappings. – ehnmark Jul 20 '11 at 13:29
  • Indeed, but like my current solution - you only specify it in one place. – Adam Houldsworth Jul 20 '11 at 13:30
  • Yep, that's pretty much what I did too. Definitely a step up from magic uri strings everywhere, but I can't help thinking there must be a way to reflect and discover the uris... – ehnmark Jul 20 '11 at 13:48
0

You have to store the Uri for a specific page on a custom class with dictionary for example or using the UriMapper. Maybe UriMapper is exatly what you are looking for.

Here is how to use it in Windows Phone http://www.windowsphonegeek.com/articles/All-about-UriMapping-in-WP7.

tbmihailov
  • 161
  • 4
  • 14