Silverlight导航

设计1个简单的导航页面

1、在MainPage.xaml文件中加入以下结构

<UserControl xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"  x:Class="SilverkightNavigation.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"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">

    <Grid x:Name="LayoutRoot" Background="White">
        <Grid.RowDefinitions>
            <RowDefinition Height="60*" MaxHeight="60" MinHeight="60"/>
            <RowDefinition/>
        </Grid.RowDefinitions>    
        <StackPanel x:Name="navigation" Grid.Row="0" Background="#FF682F2F" Orientation="Horizontal">
            <HyperlinkButton x:Name="DefaultLink" Content="首页" NavigateUri="/DefaultPage" TargetName="ContentFrame" />   注意:这里的NavigateUri属性中的DefaultPage不要加xaml后缀
            <HyperlinkButton x:Name="AboutLink" Content="关于" NavigateUri="/AboutPage" TargetName="ContentFrame" />
        </StackPanel>
        <StackPanel x:Name="content" Grid.Row="1" Background="#FF83A8D2">
            <sdk:Frame  x:Name="ContentFrame" Source="/DefaultPage" NavigationFailed="ContentFrame_NavigationFailed">     注意:Source属性中的DefaultPage不要加xaml后缀
                <sdk:Frame.UriMapper>
                    <sdk:UriMapper>
                        <sdk:UriMapping Uri="" MappedUri="/Pages/DefaultPage.xaml"></sdk:UriMapping>
                        <sdk:UriMapping Uri="/{pageName}" MappedUri="/Pages/{pageName}.xaml"></sdk:UriMapping>
                    </sdk:UriMapper>
                </sdk:Frame.UriMapper>
            </sdk:Frame>
        </StackPanel>
    </Grid>
</UserControl>

2、创建Pages文件夹,在这个文件夹中添加2个silverlight页

1)DefaultPage.xaml

<navigation:Page x:Class="SilverkightNavigation.Pages.DefaultPage"
           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"
           mc:Ignorable="d"
           xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
           d:DesignWidth="640" d:DesignHeight="480"
           Title="DefaultPage Page">
    <Grid x:Name="LayoutRoot">
        <TextBlock Text="我是default页面"/>
    </Grid>
</navigation:Page>

2)AboutPage.xaml

<navigation:Page x:Class="SilverkightNavigation.Pages.AboutPage"
           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"
           mc:Ignorable="d"
           xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
           d:DesignWidth="640" d:DesignHeight="480"
           Title="AboutPage Page">
    <Grid x:Name="LayoutRoot">
<TextBlock Text="我是About页面"/>
    </Grid>
</navigation:Page>

你可能感兴趣的:(silverlight)