我的Silverlight应用程序中有一个菜单页面。它在StackPanel中有一些HyperlinkButtons。使用带有UriMapper的导航框架将超链接映射到应用程序中的其他页面Uris。它全部出现在菜单页面的LayoutRoot Grid中。我宁愿让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>
但是将它添加到Assets / Styles.xaml非常有效。
答案 0 :(得分: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" ... />