views:

13

answers:

1

I have what amounts to a menu page in my Silverlight application. It has some HyperlinkButtons in a StackPanel. The hyperlinks are mapped to other page Uris in the app using a navigation frame with a UriMapper. It all appears within the LayoutRoot Grid of the menu page. I'd rather have the UriMapping be available to the entire application, which supposedly would mean it should be in App.xaml, but I can't figure out how to put it there so it works. Any ideas? Here's some code that resembles what I got:

<Grid x:Name="LayoutRoot">
    <Border x:Name="ContentBorder" Style="{StaticResource ContentBorderStyle}">
        <navigation:Frame x:Name="ContentFrame" Style="{StaticResource ContentFrameStyle}" Source="" Navigated="ContentFrame_Navigated" NavigationFailed="ContentFrame_NavigationFailed">
             <navigation:Frame.UriMapper>
                 <uriMapper:UriMapper>
                     <uriMapper:UriMapping Uri="/AgencyTechnical" MappedUri="/Views/AgencyTechnical.xaml"/>
                     <uriMapper:UriMapping Uri="/AgencyBusiness" MappedUri="/Views/AgencyBusiness.xaml"/>
            ...
                 </uriMapper:UriMapper>
             </navigation:Frame.UriMapper>
         </navigation:Frame>
     </Border>

     <ScrollViewer x:Name="PageScrollViewer" Style="{StaticResource PageScrollViewerStyle}" Margin="10,10,0,0" Width="640">
         <StackPanel Name="stackPanel1" Width="490" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10,10,0,0" Height="326">
             <TextBlock Text="Agency Screens" Name="AgencyScreenLabel" Style="{StaticResource MenuLabelStyle}" />
                <HyperlinkButton Name="AgencyTechInfoLink" Style="{StaticResource LinksMenuStyle}"
                    Content="Agency Technical Information" ... />
                <HyperlinkButton Name="AgencyTechInfoLink" Style="{StaticResource LinksMenuStyle}"
                    Content="Agency Technical Information" ... />

Again, how do I make this navigation frame available for the whole app? I.e in one place?


I'm Accepting @Gabriel McAdams's answer, but I had to modify it slightly. I am using the template for Silverlight Navigation Page, and there's a Resource Dictionary in App.xaml which, if gets interfered with if I add the mapping directly into the Application.Resources node. I find that I can add the mapping to the Styles.xaml and it works fine. I get a "The type 'ResourceDictionary' is inside a ResourceDictionary and does not have a key." error if I do the following:

<Application.Resources>

   <... Uri mapping here />

   <ResourceDictionary>
      <ResourceDictionary.MergedDictionaries>
         <ResourceDictionary Source="Assets/Styles.xaml"/>
      </ResourceDictionary.MergedDictionaries>
   </ResourceDictionary>

</Application.Resources>

But adding it to the Assets/Styles.xaml works great.

+1  A: 

You can put it in the Application Resources, like this:

This is your app.xaml file:

<Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    x:Class="YourSilverlightApplication.App"
    xmlns:nav="clr-namespace:System.Windows.Navigation;assembly=System.Windows.Controls.Navigation"
>
    <Application.Resources>
        <nav:UriMapper x:Key="uriMapper">
            <nav:UriMapping Uri="/AgencyTechnical" MappedUri="/Views/AgencyTechnical.xaml"/>
            <nav:UriMapping Uri="/AgencyBusiness" MappedUri="/Views/AgencyBusiness.xaml"/>
        </nav:UriMapper>
    </Application.Resources>
</Application>

This is your page (modified):

<Grid x:Name="LayoutRoot">
    <Border x:Name="ContentBorder" Style="{StaticResource ContentBorderStyle}">
        <navigation:Frame x:Name="ContentFrame" Style="{StaticResource ContentFrameStyle}" Source="" Navigated="ContentFrame_Navigated" NavigationFailed="ContentFrame_NavigationFailed" navigation:Frame.UriMapper="{StaticResource uriMapper}">
        </navigation:Frame>
     </Border>

     <ScrollViewer x:Name="PageScrollViewer" Style="{StaticResource PageScrollViewerStyle}" Margin="10,10,0,0" Width="640">
         <StackPanel Name="stackPanel1" Width="490" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10,10,0,0" Height="326">
             <TextBlock Text="Agency Screens" Name="AgencyScreenLabel" Style="{StaticResource MenuLabelStyle}" />
                <HyperlinkButton Name="AgencyTechInfoLink" Style="{StaticResource LinksMenuStyle}"
                    Content="Agency Technical Information" ... />
                <HyperlinkButton Name="AgencyTechInfoLink" Style="{StaticResource LinksMenuStyle}"
                    Content="Agency Technical Information" ... />
Gabriel McAdams