2010-10-25 41 views
0

我有我的Silverlight應用程序中的菜單頁。它在StackPanel中有一些HyperlinkBut​​tons。超鏈接通過帶有UriMapper的導航框架映射到應用中的其他頁面Uris。它全部出現在菜單頁面的LayoutRoot網格中。我寧願讓UriMapping可用於整個應用程序,這應該意味着它應該在App.xaml中,但我無法弄清楚如何把它放在那裏,所以它的工作原理。有任何想法嗎?這裏有一些類似我得到的代碼:尋找把它放在整個應用程序可用的導航框架

<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" ... /> 

同樣,我該如何讓這個導航框架可用於整個應用程序?我在一個地方?


我接受@Gabriel McAdams的回答,但我不得不稍微修改它。我正在使用Silverlight導航頁面的模板,並且在App.xaml中有一個資源字典,如果將該映射直接添加到Application.Resources節點中,該字段會受到干擾。我發現我可以將映射添加到Styles.xaml並且工作正常。我得到一個「類型'ResourceDictionary'是在一個ResourceDictionary中,並沒有一個鍵。」錯誤,如果我做到以下幾點:

<Application.Resources> 

    <... Uri mapping here /> 

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

</Application.Resources> 

但它增加了資產/ Styles.xaml的偉大工程。

回答

1

你可以把它放在應用程序資源,就像這樣:

這是你的App.xaml文件:

<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> 

這是你的頁面(修改):

<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" ... /> 
相關問題