Navigation Framework
看过 Tim Heuer(http://www.silverlight.net/learn/graphics/windows,-screens,-navigation/navigation-framework)的Navigation Framework演示,内容讲的很好,也很深入。值得好好学习。
我是跟着视频编写代码,运行时,点击跳转页面就会报错。一直以为代码写错了,检测代码,(MainPage.xaml)
<UserControl x:Class="SilverlightAppNavigationStudy.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"       
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">
<Grid x:Name="LayoutRoot" Background="White">
        <StackPanel  Orientation="Horizontal" VerticalAlignment="Top">
            <StackPanel Orientation="Vertical" Width="250">
                <HyperlinkButton  Click="HyperlinkButton_Click" Content="Home" Tag="Home"></HyperlinkButton>
                <HyperlinkButton  Click="HyperlinkButton_Click" Content="About-Us" Tag="About-Us"></HyperlinkButton>
                <HyperlinkButton  Click="HyperlinkButton_Click" Content="My Customers" Tag="Customers"></HyperlinkButton>
                
            </StackPanel>
            <navigation:Frame x:Name="MainFrame" VerticalContentAlignment="Stretch" 
                              HorizontalContentAlignment="Stretch" Margin="20" Source="/Views/HomePage.xaml">
            </navigation:Frame>
        </StackPanel>
    </Grid>
(App.xaml)
<Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
             x:Class="SilverlightAppNavigationStudy.App"
             xmlns:navcore="clr-namespace:System.Windows.Navigation;assembly=System.Windows.Controls.Navigation"
             >
    <Application.Resources>
        <navcore:UriMapper x:Key="uriMapper">
            <navcore:UriMapping Uri="Home"         MappedUri="/Views/HomePage.xaml"></navcore:UriMapping>
            <navcore:UriMapping Uri="About-Us"     MappedUri="/Views/AboutPage.xaml"></navcore:UriMapping>
            <navcore:UriMapping Uri="Customers"    MappedUri="/Views/CustomersList.xaml"></navcore:UriMapping>
            <navcore:UriMapping Uri="Customer/{id}" MappedUri="/Views/CustomerDetail.xaml?id={id}"></navcore:UriMapping>
        </navcore:UriMapper>
        <navcore:UriMapper x:Key="uriMapper2">
            <navcore:UriMapping Uri="Home"         MappedUri="/Views/HomePage.xaml"></navcore:UriMapping>
        
            <navcore:UriMapping Uri="Customers"    MappedUri="/Views/CustomersList.xaml"></navcore:UriMapping>
            <navcore:UriMapping Uri="Customer/{id}" MappedUri="/Views/CustomerDetail.xaml?id={id}"></navcore:UriMapping>
        </navcore:UriMapper>
    </Application.Resources>
</Application>
搜索,发现有很多网友出现一样的问题,幸好有网友提示 navigation没有加 UriMapper,
回到MainPage,在navigation:Frame x:Name="MainFrame" 后加上 UriMapper="{StaticResource uriMapper}"
重新编译,通过。运行良好。不过有个疑问,Tim Heuer的视频是没有加的,难道还有其他方法?
 
                     
                    
                 
                    
                
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号