Advertisement

Silverlight 3: Navigation URI Routing

One of the new features in Silverlight 3 is providing an application navigation framework via the Frame and Page controls in the APIs.  If you saw my guide to Silverlight 3, you may have seen the section on navigation which describes the functionality and as well has a link to a video tutorial about it.

I wanted to augment that tutorial with some additional information about URI routing, which I think is one of the great features of the framework.  You see typically your UriMapper might have a 1:1 mapping and look something like this (note in my sample here I’m putting this in App.xaml, but the model may change in the future of where you can/should place UriMapper):

   1: <Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   2:              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
   3:              x:Class="NavigationSample.App"
   4:              xmlns:navcore="clr-namespace:System.Windows.Navigation;assembly=System.Windows.Controls.Navigation"
   5:              >
   6:     <Application.Resources>
   7:         <navcore:UriMapper x:Key="uriMapper">
   8:             <navcore:UriMapping Uri="About-Us" MappedUri="/Views/AboutPage.xaml" />
   9:         </navcore:UriMapper>
  10:     </Application.Resources>
  11: </Application>

But what if you still wanted to provide friendlier routes, obfuscate the physical location of the view, but handle the default scenario?  You can as long as you follow your own naming conventions.  Take for instance if we contain all our pages in a folder called Views in our application.  We could then map our routes like this:

   1: ...
   2: <navcore:UriMapper x:Key="uriMapper">
   3:     <navcore:UriMapping Uri="{}{page}" MappedUri="/Views/{page}.xaml" />
   4: </navcore:UriMapper>
   5: ...

You could also follow some naming conventions if you wanted to make sure you limited it to only pages or something so you require the view page to be named SomethingPage.xaml and then can have a route like:

   1: ...
   2: <navcore:UriMapper x:Key="uriMapper">
   3:     <navcore:UriMapping Uri="{}{page}" MappedUri="/Views/{page}Page.xaml" />
   4: </navcore:UriMapper>
   5: ...

The navigation routes are read top down so you can still have explicit (or additional) routes in addition to the default.  So given:

   1: ...
   2: <navcore:UriMapper x:Key="uriMapper">
   3:     <navcore:UriMapping Uri="About-Us" MappedUri="/Views/AboutPage.xaml" />
   4:     <navcore:UriMapping Uri="History" MappedUri="/Views/AboutPage.xaml" />
   5:     <navcore:UriMapping Uri="{}{page}" MappedUri="/Views/{page}.xaml" />
   6: </navcore:UriMapper>
   7: ...

A request to About-Us, History or About would navigate to /Views/AboutPage.xaml regardless.  This provides you some flexibility and granularity in your implementation and also provides additional SEO points for your content.

I really like the UriMapper in the navigation framework and have been lobbying to change the default templates Visual Studio spits out to use the UriMapper by default.  It provides you with a cleaner (and perhaps shorter) URI as well as obfuscates your “code” from your URI logic.  Be sure to check out the video if you aren’t familiar with the framework at all.

I hope this helps and would love to know what you think about the navigation framework?


This work is licensed under a Creative Commons Attribution By license.

  1. 3/22/2009 2:58 PM | # re: Silverlight 3: Navigation URI Routing
    This is cool as Silverlight can be hosted in ASP.NET, ASP.NET MVC and on the desktop now. When hosted in ASP MVC, I think the routing tables should match to make the data access easier cleaner (especially when using REST). I think this makes integrating the two easier.
  2. 3/22/2009 6:20 PM | # re: Silverlight 3: Navigation URI Routing
    This is great stuff. One thing I don't understand is why you cant use any other key for the UriMapper and its case sensitive. So if you try any other key besides "uriMapper" nothing will work. I guess there is a default UriMapper and your overriding it with this one.
  3. 3/22/2009 6:43 PM | # re: Silverlight 3: Navigation URI Routing
    Thanks Tim!
    One question! Will there be MVC framework/pattern for Silverlight?
    If so, how will this navigation framework work with that?
  4. 3/22/2009 7:48 PM | # re: Silverlight 3: Navigation URI Routing
    Troy -- 'uriMapper' is a beta thing for now. The main reason is that you cannot traverse the resource collection in Silverlight right now, so we look for a specific name. We're already thinking about where the resource lives anyway to make it easier to do this, but for now the beta limitation of a specific name is required.

    Anita -- you can use an MVC model with Silverlight sure. We're not providing anything specific right now. Look at Prism 2 for some patterns (MVVM).
  5. 3/22/2009 10:00 PM | # re: Silverlight 3: Navigation URI Routing
    I've been trying to get the navigationservice to navigate to an assembly/type that is not directly referenced in my main SL3 App. I've tried loading the assembly into the AppDomain (which works) and then add the AssemblyPart to the deployment parts collection (which works), but when i nav using asmname;component/typepath.xaml it fails because it notices the ;component which causes the ResourceManager to load the assembly again but the stream it retrieves is actually the type not the assembly. After hacking around I've noticed the PageContentLoad/ResourceManager may have faulty logic when accessing External types. To much to list here. Currently in SL2, I load up additional Dlls and then navigate to them using my own custom navigation service and infrastructure (frame/page) similar the SL3, but lacks the Browser Journal integration and I would like to convert to SL3. This is for an Application Plugin Framework similar to Prism 2.0. Any comments/perspective is appreciated.
  6. 3/23/2009 7:49 AM | # re: Silverlight 3: Navigation URI Routing
    Does this rely on any SL3 runtime features? If not, could it be pushed out as part of the Silverlight Toolkit for early adopters?
  7. 3/23/2009 8:36 AM | # re: Silverlight 3: Navigation URI Routing
    Hi Pete -- yes this is a Silverlight 3 feature -- Silverlight 3 is for early adopters ;-). There are a few Silverlight 2 frameworks out there that folks have created that you may want to look at.
  8. Gravatar
    3/24/2009 3:38 AM | # re: Silverlight 3: Azure Tables
    Hi Tim,

    How can one access Azure Table Storage from Silverlight 3.

    If this is the wrong forum, can you give directions.

    Rob



  9. 3/25/2009 9:55 AM | # re: Silverlight 3: Navigation URI Routing
    Tim,

    Is there a way to stop the Frame from re-loading a Page that has previously been navigated to?

    The behaviour I'm trying to implement is allowing a user to switch pages but keep the context of what they were doing. At the moment if the user changes a value on a page, then switches to another page and back again their change is lost.

    Phil
  10. 3/27/2009 1:50 AM | # re: Silverlight 3: Navigation URI Routing
    Tim, I have a little question about navigation. I made a page with 2 frames on it. When I do Frame1.Navigate(Uri) then both frames navigate to that page.... Is that the wanted functionality? I'm trying to use the frames as regions in my application.... Is that supported?
    Patrick
  11. 3/30/2009 11:11 AM | # re: Silverlight 3: Navigation URI Routing
    Patrick -- state management is a good question. Let me do some digging to see what our plans are here.
  12. 3/31/2009 1:43 PM | # re: Silverlight 3: Navigation URI Routing
    Hi Tim,
    Do you have plans to implement Navigation to a page object
    Navigate(new MyPage());

    Thanks,
    Anthony.
  13. 3/31/2009 2:27 PM | # re: Silverlight 3: Navigation URI Routing
    Tim,

    We've just finished a SL2 business application that was heavily navigation based. We were using browser book marks that contained the view to navigate to and view specific state, e.g. the ID of the entity to display on that view. Is there any plan to extend navigation to allow this view specific state?

    Greg
  14. 3/31/2009 2:41 PM | # re: Silverlight 3: Navigation URI Routing
    Greg -- yes you can do that today by using parameters passed into the view for the navigation. If you are talking about automatic state management between forward/back type implementation, this is something we are considering.
  15. 4/1/2009 6:54 AM | # re: Silverlight 3: Navigation URI Routing
    @ It provides you with a cleaner (and perhaps shorter) URI as well as obfuscates your “code” from your URI logic.

    I think you mean separates, not obfuscates. If you are wondering why your lobbying is failing, then maybe the Visual Studio guys are saying to themselves, "Why does Tim like obfuscated code?" ;-) Method ~ of ~ epic fail ;-)
  16. 4/1/2009 9:16 AM | # re: Silverlight 3: Navigation URI Routing
    John -- no, I actually should have written that it obfuscates your code paths from your URI logic. If you don't use URI mapping (and there is nothing wrong with that approach), then as a savvy end user I know that /Views/Folder/MyCustomerDetailPage.xaml is located in a specific place in your application resources -- versus 'Customer' which could map to something where I don't know. Of course none of this matters to the end user :-)
  17. 4/1/2009 9:40 AM | # re: Silverlight 3: Navigation URI Routing
    Just say, "URI mapping hides your physical resource layout from the end user. Instead, the user sees a search-engine friendly URI." Of course, this isn't entirely true. Search engines do not index fragments. However, the idea behind deep linking is to provide a way for them to do so.

    By the way, deep linking isn't a new idea. Stephen Meschkat, the co-creator of Gmail, has presented at the past two Computer Human Interaction conferences on how they designed a "hard/soft state vocabulary" for front-end engineers and back-end engineers to grok. Silverlight just makes it simpler to read, but is still working out the "simpler to implement" part -- soft state is probably an "essential complexity".

    I've posted my feedback on UriMapping to the Silverlight forums, hijacking a thread dedicated to a previous but related bug report. Feedback appreciated (and I've provided my email if you want to converse off-web).

    silverlight.net/forums/p/84313/199609.aspx#199609

    Although looking at your blog post a second time (right before clicking send), I see another issue:

    @You could also follow some naming conventions if you wanted to make sure you limited it to only pages or something so you require the view page to be named SomethingPage.xaml and then can have a route like: <navcore:UriMapping Uri="{}{page}" MappedUri="/Views/{page}Page.xaml" />

    First, why the {} prefix in front of {page}? Second, how do you handle scenarios where it cannot map to a Uri (you are making the implicit assumption that we're one-to-one and onto, which will result in runtime errors)?
  18. 4/1/2009 12:20 PM | # re: Silverlight 3: Navigation URI Routing
    John, the {} is basically escape characters to indicate the following content is not to be treated literally. In my example (and it was just an example), you are correct, if you don't follow your naming conventions and have an explicit mapping, then the user requests a URI that isn't there, a runtime error would occur. URI mappings read like a book though, reading top-down (ok, an odd book). So explicit is checked first, then you could provide an overall fallback in the end. In the event a mapping isn't found, then the developer should have that error case handled and capture the exception.

    URI mapping won't work for everyone of course, but it is a good alternative style to using the navigation framework.
  19. 4/1/2009 2:02 PM | # re: Silverlight 3: Navigation URI Routing
    @So explicit is checked first, then you could provide an overall fallback in the end.

    Computer Science has created a model of logic called "decision tables", where there is this concept called "bottom" or "undefined". If you specify explicit first, then you still can fall-through to the pattern matching cases with the potential to be undefined. Defining implicit later on still guarantees the function will no longer be one-to-one and onto. Without this functional property, you will get exceptions.

    You seem to be conflating overlapping pattern matches with undefined navigation paths. I figure I'm to blame here, I'm not the best communicator... ;-) so I thought I'd try and clear that up: Overlapping pattern matching is resolved through priorities. Priorities cannot handle undefined resources, by definition of an undefined resource you can't assign a priority to it. So I'm not talking about priorities of the routing algorithm.

    @In the event a mapping isn't found, then the developer should have that error case handled and capture the exception.

    Be sure to document this exception handling as a best practice. On the Web, errors are handled much more gracefully than an unhandled CLR exception.

    Still, my point shows the intimate relationship between hard and soft state that Meschkat talks about in his CHI workshops.

    Also, you really ought to make the default behavior be to have a 404-like error page instead of an exception. The Browser doesnt die on a bogus link. Why should an SL3 app?

    @URI mapping won't work for everyone of course, but it is a good alternative style to using the navigation framework.

    You can basically choose to let me contribute brain cycles to improving SL3. I can't force you. ;-)

    Still waiting feedback on whether UriMapping will only be able to GET application local resources. What's interesting is that if non-local resources werre a part of the UriMapper design in the first place, then you'd definitely have to support Error Page functionality as you can't guarantee a mobile application will have connected access to a View.

    Are you up for discussing this? ;-)
  20. 4/1/2009 3:21 PM | # re: Silverlight 3: Navigation URI Routing
    John -- goot point on 404-ish behavior. In face maybe the ending catchall {}{page} would be your 404-ish behavior...good idea.

    As to your last question...are you wanting to have a URI map like:

    <navcore:UriMapping Uri="FooBar" MappedUri="/SilverlightClassLibrary1;component/SilverlightControl1.xaml" />

    Yes you can do that.
  21. 4/2/2009 7:42 AM | # re: Silverlight 3: Navigation URI Routing
    I think UriMapper should probably have an ErrorPage property (of type Uri), with a non-null default value.

    I am not sure how {}{page} would know to do what you are saying, unless:

    You are thinking of using the last element in the UriMappings collection as a sort of "null lambda expression", i.e., "x goes to Nothing" or "x goes to void" or "x goes to unit".

    If so, that's an interesting idea. It gives me a different though, though. Perhaps UriMapper should have an enumerated type property specifying fall-through behavior? I can see at least two ways of people wanting fall-through to interact with Exceptions:

    Conceptually, you can have matching errors and routing errors. (1) A matching error is where the UriMapper couldn't find a UriMapping object with a Uri property that matched the requested Uri from wherever in the app. (2) A routing error is where the UriMapper found at least one valid match, but UriMapper.MapUri() failed to locate the matched Uri's specified MappedUri physical resource.


    A matching error should only occur at the end of the loop if no match was found. An enumerated type could be MatchErrorBehavior.DelegateToCaller (don't raise and throw the exception from within UriMapper.MapUri(), instead let the caller fail and recover as the caller is in best position to customize how to react) and MatchErrorBehavior.RedirectToErrorPage (the generic "I don't want to handle this event" handler -- allow the Uri in the ErrorPage property to load into the navigation frame).

    A routing error can occur whenever there is a valid match but no associated MappedUri. The association can break down for a number of reasons. This sort of checking is necessary - it is pretty much analagous to how the CLR ensures bounds checking on arrays. Let me know if you want me to list the members of this enumerated type. At a minimum, it should mirror Http errors and also support something LIKE BUT PERHAPS NOT EXACTLY: RoutingErrorBehavior.FallThroughOnLocationError and RoutingErrorBehavior.DelegateToCallerOnLocationError and RoutingErrorBehavior.RedirectToErrorPage.

    The hard error case to describe is when you've fallen through on a locator error, but never found another match later on with a valid MappedUri. I can't think of a name to describe this that is shorter than RoutingErrorBehavior.FourScoreAndSevenYearsAgoOurFathersBroughtForthOnThis ContinentANewNationConceivedInLibertyAndDedicatedToThePropositionThatAllMenAreCreatedEqual ;-)

    The reason for mimicking Http errors is that it should be possible to do:

    <navcore:UriMapping Uri="FooBar" MappedUri="http://www.example.com/rubber-ducky.xaml" />

    For various good OO design reasons, I don't want to store my Views in any assemblies, not even dynamically loadable remote assemblies apart from the application's main assembly. Glen (the commenter above) is doing the approach you describe (and apparently describing a severe bug):

    <navcore:UriMapping Uri="FooBar" MappedUri="/SilverlightClassLibrary1;component/SilverlightControl1.xaml" />

    Apart from the fact the approach described by Glen won't scale for my application, I also want a Workspace/Conversation style model similar to Redhat's JBoss Seam integration framework (but not having to deal with much of the lame request/response page cycles of the web and frankly even ajax). I'm just talking good scalable OO application design, imho.
  22. 4/6/2009 7:12 AM | # re: Silverlight 3: Navigation URI Routing
    By the way, I assumed this was the case, but have you talked to David Hill of MSFT P&p? I always forget MSFT has over 70,000 employees and the likelihood that "one hand knows what the other is doing" is very low. He provided a navigation framework in SL2, called Helix, although it has similar problems to your navigation framework.

    However, I didn't like David's design goals. A quote taken from his blog: "The navigation framework presented here is similar in a lot of ways to the WPF model but (I think) it is simpler and more flexible. In particular it addresses three of my main greivances with the WPF model - it provides an 'open' linking model, it makes it easier to pass state between pages, and it allows you to more easily unit test the navigational structure of your app."

    In particular, passing state between pages is very non-OO. It forces you to deal with permutations at too high a level of abstraction, requiring ad-hoc case statements to be written. Why do all that work for simple "Form Entry Trains"? This is an approach that in my experience ultimately ends in heartbreak. I would not want to design a subsystem for any domain that encourages passing concrete object references around. I also therefore disagree that it makes it easier to test the navigational structure - only in very static compile-the-world scenarios is is unit testable. In such scenarios, its darn easy to get path coverage -- especially when your project is small.
  23. 5/15/2009 2:16 AM | # re: Silverlight 3: Navigation URI Routing
    Hi Tim,
    I have a question similar to Anthony's post.
    Why there is not, like in WPF, a Navigation object that accept a parameter objet?

    Navigate(new MyPage());

    Thanks
    Gianni



  24. 5/24/2009 1:44 PM | # re: Silverlight 3: Navigation URI Routing
    Gianni - the navigation framework is still in beta right now and things like this are being considered.
  25. 7/2/2009 8:33 AM | # re: Silverlight 3: Navigation URI Routing
    Tim

    Im trying to create an ad-hoc navigation inside an app using the SL3 Navigation Framework and PRISM. I have a Frame in my "main page", but when I try to execute Navigate(uri) on it, it throws a NullReference exception. I have noticed that the NavigationService of the Frame has a null UriMapper, but I'm totally sure it's set up in the App.xaml as indicated in the screen cast.

    Anything else I need to do?

    Thanks in advance
  26. 7/22/2009 11:32 PM | # re: Silverlight 3: Navigation URI Routing
    Hi Tim,
    Used it in the Beta and worked really cool, have installed the final release and now I'm getting error "Message: Unhandled Error in Silverlight Application
    Code: 4004
    Category: ManagedRuntimeError
    Message: System.ArgumentException: Navigation is only supported to relative URIs that are fragments, or begin with '/', or which contain ';component/'.
    Parameter name: uri" errors, what has changed since the beta?
  27. 7/22/2009 11:39 PM | # re: Silverlight 3: Navigation URI Routing
    Adriaan - look at 3.16,3.17 from msdn.microsoft.com/.../cc645049%28VS.95%29.aspx and see if you are affected by this.
  28. 7/24/2009 4:07 AM | # re: Silverlight 3: Navigation URI Routing
    Hi Tim,
    I have found my problem, with SL3 you need to specify UriMapper= for the frame, which I did not have. The error message is not very help full when you do not have a UriMapper specified, but my problem is ok now thanks
  29. 8/14/2009 6:27 AM | # re: Silverlight 3: Navigation URI Routing
    Hi Tim,
    it is nice work
    but Your code does not work in Silverligth 3!!!
    Message: System.ArgumentException: Navigation is only supported to relative URIs that are fragments, or begin with '/', or which contain ';component/'.
    Miro
  30. 8/14/2009 7:05 AM | # re: Silverlight 3: Navigation URI Routing
    Hi Tim,
    I have found where was the problem, uf.....
    For the Silverlight 3 You have to
    declare UriMapper property in the navigation:Frame, see bellow
    <navigation:Frame x:Name="MainFrame" HorizontalContentAlignment="Stretch" Background="Yellow"
    VerticalContentAlignment="Stretch" Margin="20" Source="Home"
    UriMapper="{StaticResource uriMapper}"/>

    Miro
  31. 8/14/2009 8:26 AM | # re: Silverlight 3: Navigation URI Routing
    miro - yes this is a pre-release post. you can put the code in a resource still like you noted or as a child of Frame as well.
  32. 8/18/2009 4:43 AM | # re: Silverlight 3: Navigation URI Routing
    Hey Tim,

    Great job with your Silverlight Navigation Tutorials. The code works fine with SL3. Great job!

    However, have a look at the image below (see the URL in the IE window)

    http://img249.imageshack.us/i/navdemo.jpg/

    The URL doesn't change no matter which hyperlink I click. But in your video, whenever you click on a particular customer, the URL contains that customer's ID (Something like /Customers/2).

    I am using SL3 with VS2008 and IE8.

    Sorry If I have missed something silly, but hey I am a Silverlight n00b!

    Thanks

    - Vinod
  33. 8/18/2009 7:37 AM | # re: Silverlight 3: Navigation URI Routing
    Vinod -- make sure you have the <iframe> specified in the <object> tag for the plugin. It has to have a specific name now in RTM:

    <iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe>

    This will enable the URL working again.
  34. 8/18/2009 7:59 AM | # re: Silverlight 3: Navigation URI Routing
    It worked!

    Thanks a ton for a quick reply.

    I have seen a lot of SL tutorial videos from you. They are of great help. Keep up the great work.

    - Vinod
  35. 9/12/2009 9:11 AM | # re: Silverlight 3: Navigation URI Routing
    Hi Tim,

    Great framework.

    In the default Navigation Project of Visual Studio, it has this line:

    <uriMapper:UriMapping Uri="/{pageName}" MappedUri="/Views/{pageName}.xaml"/>

    You talk a little about that in the above posts, but I don't get how this works as far as the {pageName} reference. It obviously takes whatever is passed to it as a page name, and passes it to the second use of {pageName}, but how is this being done by the XAML parser? I can even change the name of the variable in both places and it still works.

    It appears that somehow a variable is being defined and then used. Is this being done by the UriMapping class or is this a feature of XAML or ??. I have read up on the MarkupExtension classes, but I still don't see how this works.

    Greg
  36. 9/13/2009 6:54 AM | # re: Silverlight 3: Navigation URI Routing
    I took a look at the UriMapping class in Reflector, and it looks like what is occuring with {pageName} is that it is being processed as a regex in the MapUri function. Is this correct? It's no big deal, I was just trying to understand what was going on in the code.

    Greg
  37. 9/13/2009 3:05 PM | # re: Silverlight 3: Navigation URI Routing
    Greg -- looks like you figured it out. Yes it is basic regex in the runtime. you could put {foo} if you wanted :-) it makes it so you could do something like {pageName}/{customerId} and use those monikers in the mapping.
  38. 10/8/2009 7:03 PM | # re: Silverlight 3: Navigation URI Routing And mailto
    Hy, im having problem in using UriMapper and mailto in a NavigateUri from a HypperLinkButton, can`t use mailto that open the window error from the VS2008 Silverlight 3 Template...
  39. Gravatar
    10/12/2009 9:07 AM | # re: Silverlight 3: Navigation URI Routing
    Uri mapper is not working, the browser address and history is not working. I thought it was me but I down loaded your project add the line UriMapper="{StaticResource uriMapper}" to the Nav Frame. it will navigate with in the application. but the URL address doesn't change and no history point have been added. has this been removed form the final release.
  40. Gravatar
    10/12/2009 10:27 AM | # re: Silverlight 3: Navigation URI Routing
    you had stated it above but I didn't understand what you meant your Iframe on the html page has to have an id="_sl_historyFrame"

    this blog helped but if you look at my post above and this you can get the demo to work
    geekswithblogs.net/.../...avigation-framework.aspx
  41. 11/6/2009 2:29 AM | # re: Silverlight 3: Navigation URI Routing
    Damn ... I ve implemented library caching. My menu still work : i can access to all my liste (liste custumers, listItem ...)
    Menu (popup on clic on elipse on image) -> list View

    But i can't go to all my detail vue
    list view -> detail view

    Is it possible to send more than one var in the URL ?

    /appliSilver/id={id}/lang={language} .......
  42. 11/6/2009 3:23 AM | # re: Silverlight 3: Navigation URI Routing
    Nk54 yes you can have more vars but list them as query string format /appliSilver/id={id}&lang={language}
  43. 11/12/2009 7:01 AM | # re: Silverlight 3: Navigation URI Routing
    which assembly required for it...This is not mentioned in information.
  44. 11/25/2009 5:50 PM | # re: Silverlight 3: Navigation URI Routing
    I am loading a resource dictionary in my app.xaml page. I get an error when i try to run my project. I get a XamlParseException on Initialize of the app.xaml.cs

    Local values are not allowed in resource dictionary with Source set [Line: 0 Position: 0]

    Is it not possible to include both in the app.xaml file.

    <Application.Resources>
    <ResourceDictionary Source="Resources/Style.xaml" />
    <navcore:UriMapper x:Key="uriMapper">
    <navcore:UriMapping Uri="Login" MappedUri="Pages/Login.xaml" />
    <navcore:UriMapping Uri="Register" MappedUri="Pages/Login.xaml" />
    </navcore:UriMapper>
    </Application.Resources>
  45. 11/25/2009 6:02 PM | # re: Silverlight 3: Navigation URI Routing
    I figured out my problem. Once i added the uriMapper i needed to make my resources dictionary into a merged resource dictionary. Here is the solution if anyone else has this problem later.

    <Application.Resources>
    <ResourceDictionary>
    <ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="Resources/Style.xaml" />
    </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
    <navcore:UriMapper x:Key="uriMapper">
    <navcore:UriMapping Uri="Login" MappedUri="/Pages/Login.xaml" />
    <navcore:UriMapping Uri="Register" MappedUri="/Pages/Login.xaml" />
    </navcore:UriMapper>
    </Application.Resources>
  46. 12/2/2009 10:01 AM | # re: Silverlight 3: Navigation URI Routing
    Are there any known issues with mixing SL3 pages and ASPX pages regarding navigation? I have implemented Navigation with success when accessing SL3 pages alone. But problems occur if I navigate from SL3 to ASPX to SL3, etc., and then try using the browser back/forward buttons. Loading the SL3 pages will occasionally fail when coming from an ASPX page (appearing to get "stuck" on the ASPX page, even though the URL changes properly).
  47. 12/2/2009 10:04 AM | # re: Silverlight 3: Navigation URI Routing
    Kevin -- do you have a reproduction URL we could see?
  48. 12/3/2009 12:10 PM | # ValidateXaml fails when using a navigation frame
    Hey Tim,
    Thank you for the informative tutorial. I have been trying to implement the navigation framework, and inserting a navigation frame in the xaml gives me: "ValidateXaml" task failed unexpectedly, could not find the implementation for method navigate in System.Windows.Controls.Frame. I have rechecked, deleted and added references, and even reinstalled my entire development environment and it still shows the same error. Following is the xaml which is giving the error:
    <UserControl
    xmlns="schemas.microsoft.com/.../presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
    x:Class="test.MainPage"
    Width="640" Height="480">

    <Grid x:Name="LayoutRoot" Background="White">
    <navigation:Frame Margin="292,188,248,192"/>
    </Grid>
    </UserControl>

    Please help!
  49. 12/3/2009 2:47 PM | # re: Silverlight 3: Navigation URI Routing
    Did you start with the Silverlight Navigation template?
  50. 1/7/2010 4:37 PM | # re: Silverlight 3: Navigation URI Routing
    Hi Tim

    I just begun to use the navigation framework, I saw your video but qhen I create a new application from the template I can't use de mapping like you show it in the video. So... I tried to use the mapping in the MainPage.xaml like the template does but I can't call a page with an argument that has to be sent, can you help me please? how can I send the information
  51. 1/21/2010 11:03 PM | # re: Silverlight 3: Navigation URI Routing
    Can you please give me sample application for my following requirement -
    I want a layout with -
    1. Header.
    2. Left Navigation (Collapsible Menu)
    3. Content Page. (It should change as per the click on Collapsible Menu item).
    4. Footer (with Current Content Page Name).
    5. One Full Screen Button.
    Can you please send me the above functionality ASAP. I have an urgent requirement. All

    should be in Silverlight Application only.

    |--------------------------------------------------------|
    | Header.xaml |
    |--------------------------------------------------------|
    | | |
    |left.xaml | content.xaml |
    | | |
    |Full Screen Btn| |
    |--------------------------------------------------------|
    | footer.xaml |
    |--------------------------------------------------------|
  52. 2/28/2010 9:06 AM | # re: Silverlight 3: Navigation URI Routing
    hello,

    thank you for all your stuff on silverlight.
    at this point I can't have UriMapper working when I try to put it un App.xaml.
    Even you sample project fail. I must put the mapper in the frame by using the tag <navigation:Frame.UriMapper>

    Any idea.

    thank you in advance

    thierry
  53. 3/4/2010 2:05 PM | # re: Silverlight 3: Navigation URI Routing
    Thanks for the great information... I'm just having a small problem though after adding another page with a "mailto:" link on it, which I've read elsewhere is supposed to work within Silverlight. Unfortunately though I think the Uri mapping is causing me trouble since I get the following error when clicking the link:

    "Page not found: "mailto:emailaddresshere""

    Any feedback you can provide would be great... Thanks again. D.
  54. 3/4/2010 5:03 PM | # re: Silverlight 3: Navigation URI Routing
    It was obvious really... Just needs _blank or _self as the target name... When I first tried that, it was causing another issue which is what turned me away from it, but turns out the issue is with Internet Explorer 8 apparently... It works as expected in Chrome.
  55. 3/18/2010 6:28 PM | # re: Silverlight 3: Navigation URI Routing
    I using SL3 and VS08 and am having problems navigating to XAML files that are linked in VS (instead of being actual files). I keep getting "no XAML found" errors when navigating to a linked file. Is there any workaround for this?
  56. 3/24/2010 10:29 AM | # re: Silverlight 3: Navigation URI Routing
    Hi Tim, could you please tell whether it is possible to combine two things in a SL3 app: (1) tabbed interface a la Visual Studio, and (2) navigation capabilities together with Uri mapping. When the user clicks a side-bar item, a tab (corresponding to the clicked side-bar item) should be created (here I'm not speaking of the case when it already exists), and after that a page must be loaded into this tab and the browser's address bar should be updated with the corresponding Url. Fortunately I do need to isolate history within each tab.

    One more thing needs to be mentioned: loading page into the selected tab must be done not by the page's path but by the name of the corresponding Presenter. So probably some UriMapping stuff must be moved from XAML to code-behind (?).

    I will greatly appreciate your help! Thank you.
  57. 3/24/2010 12:03 PM | # re: Silverlight 3: Navigation URI Routing
    Regarding my previous post:
    I got a rough idea... I'm not sure this will work: use the standard SL Navigation Application, but **somehow** intercept creation of a page and instead of that create a new **tab**, then create corresponding Presenter and inject new tab into this Presenter so that Presenter can place its View (page) onto this tab. What do you think?
  58. 5/29/2010 10:38 PM | # re: Silverlight 3: Navigation URI Routing
    Thank you so much! This site has great content. Keep it up.
  59. 5/30/2010 1:42 PM | # re: Silverlight 3: Navigation URI Routing
    It seems your code does not work in Silverligth 3
    Message: System.ArgumentException: Navigation is only supported to relative URIs that are fragments, or begin with '/', or which contain ';component/'.
  60. Gravatar
    6/14/2010 4:31 AM | # SEO
    They are selfish to each other, how can they get a solution if they never want to receive another's idea.
  61. 6/16/2010 5:08 AM | # Silverlight 3: Navigation URI Routing
    Hi Tim,

    Trying to get this URI mapping to work with regards to navigation regarding frames. We are trying to pass a page through using a hyperlink button and tags so that it is displayed in a frame. It seems there are 2 ways to do this: either within the code, or to use the Source option in Blend - either way it doesn't seem to be working properly (think we might have messed up and there are two sets of code trying to do it). We were also thinking of just using page switching, but are unsure whether frames outweigh the benefits of page switching. Could you offer some advice, or a direction in which we cud go?
    Thanks very much
  62. 6/23/2010 9:22 PM | # re: Silverlight 3: Navigation URI Routing
    Hi Tim,

    I have a main.aspx which uses forms authentication. It has a logoff button which when clicked redirects to ligin.aspx page. The main page has also silverlight content when i click on logoff the silverlight content is still active and the page is not redirected to login.aspx ? Please help me....

    Thanks In Advance
  63. 7/26/2010 7:57 AM | # re: Silverlight 3: Navigation URI Routing
    I think the navigation method of silverlight is absolutely ridiculous. were the project managers high when they decided to handle it this way?
  64. 8/10/2010 10:15 AM | # re: Silverlight 3: Navigation URI Routing
    is it me or the code doesn't work in silverlight 3?
  65. 8/13/2010 4:50 AM | # re: Silverlight 3: Navigation URI Routing
    Hello Tim,

    I'm following your post for a long time now and have learned a lot from your tutorials.

    I am developing a silverlight 3 web app currently and i was wondering, if there is a way to make the URI extentionless, i mean without the *something*TestPage.html?

    for the info, I plan to deploy the app on a IIS 5.1(or 6.0) server.
  66. 8/17/2010 9:33 AM | # re: Silverlight 3: Navigation URI Routing
    Since I have been reading your useful article and following them minutely for the sake of learning, I am excited to go through topic on "Silverlight 3: Navigation URI Routing" and found your guide very helpful. Its an excellent tutorial.
  67. 8/26/2010 5:46 PM | # re: Silverlight 3: Navigation URI Routing
    This is cool as Silverlight can be hosted in ASP.NET, ASP.NET MVC and on the desktop now. When hosted in ASP MVC, I think the routing tables should match to make the data access easier cleaner (especially when using REST). I think this makes integrating the two easier. I would like to join it if possible. There is just good chance to know many new people.
  68. 8/27/2010 4:16 AM | # re: Silverlight 3: Navigation URI Routing
    Hi Tim,
    Great article but I have a bit of a funny one. I have implemented navigation framework quite happily in Silverlight 4 but when my app comes up the very first time the Back button is immediately enabled. Clicking Back displays the error message "Content for the URI cannot be loaded. The URI may be invalid.
    Parameter name: uri

    at System.Windows.Navigation.NavigationService.NavigateCore(Uri uri, NavigationMode mode, Boolean suppressJournalAdd, Boolean isRedirect)
    at System.Windows.Navigation.NavigationService.Journal_Navigated(Object sender, JournalEventArgs args)
    at System.Windows.Navigation.Journal.OnNavigated(String name, Uri uri, NavigationMode mode)
    at System.Windows.Navigation.Journal.UpdateObservables(JournalEntry currentEntry, NavigationMode mode)
    at System.Windows.Navigation.Journal.AddHistoryPoint(JournalEntry journalEntry)
    at System.Windows.Navigation.Journal.AddHistoryPointIfDifferent(String newState)
    at System.Windows.Navigation.Journal.Browser_Navigated(Object sender, EventArgs eventArgs)
    at System.Windows.Navigation.Journal.<>c__DisplayClass3.<InitializeNavigationState>b__2(Object sender, NavigationStateChangedEventArgs args)
    at System.Windows.Interop.SilverlightHost.RaiseNavigationStateChanged(String oldState, String newState)
    at System.Windows.Interop.SilverlightHost.OnNavigationStatePollingTick(Object sender, EventArgs e)
    at MS.Internal.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args)
    at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, String eventName)"

    What on earth am I doing wrong?

    Thanks
    Dave.

 
Please add 3 and 7 and type the answer here:
First time here? You are looking at the most recent posts. You may also want to check out older archives. Please leave a comment, ask a question and consider subscribing to the latest posts via RSS or email. Thank you for visiting! (hide this)