1
votes

I am having the problem. When the page loads first time, it loads 'AlbumView.xaml' in the frame. When I click on the back button, it throws the following error message:

An unhandled exception('Unhandled Error in Silverlight Application:4004' Category: ManageRuntimeError Message: System.ArgumentException: Content for the URI cannot be loaded. The URI may be invalid.

Here is the code:

  <Grid Grid.Row="1" Name="Main">

      <sdk:Frame Source="About"  Name="MainFrame" BorderThickness="2">
        <sdk:Frame.UriMapper>
                <sdk:UriMapper>

                    <sdk:UriMapping 
            Uri="About" 
            MappedUri="/Views/AlbumView.xaml"/>

                    <sdk:UriMapping 
            Uri="Categories" 
            MappedUri="/Views/AlbumCategoriesView.xaml"/>


                </sdk:UriMapper>
            </sdk:Frame.UriMapper>
        </sdk:Frame>

 </Grid>

Just wonder is it a known problem, or just doing smth wrong?

Cheers.

1

1 Answers

1
votes

The problem is that you have no mapping to for the empty Uri "". You have the Frame Source set to "About". When the application has loaded it navigates to "#About". Press the back button the "About" disappears leaving the UriMapper to attempt to map "". You don't have one so it fails.

Adding an additionall mapping of:-

<sdk:UriMapping Uri="" MappedUri="/Views/AlbumView.xaml" />

Would prevent an error being seen.

However consider renaming your "AlbumView.xaml" to "About.xaml" and your "AlbumCategoriesView.xaml" to "Categories.xaml". You can then use a more traditional mapper:-

<sdk:Frame Source="/About" Name="MainFrame" BorderThickness="2">
    <sdk:Frame.UriMapper>
        <sdk:UriMapper>
            <sdk:UriMapping Uri="" MappedUri="/Views/About.xaml" />
            <sdk:UriMapping Uri="/{pageName}" MappedUri="/Views/{pageName}.xaml" />
        </sdk:UriMapper>
    </sdk:Frame.UriMapper>
</sdk:Frame>

Now you can create new views using the name you want to appear in the URL for the view without the need to extend the mapping list every time. (Note also the use of a preceeding /, this is common practice and necessary for the Uri="/{pageName}" to work).