0

我尝试在 student.xaml 页面上的 mainpage.xaml 中添加一个超链接。student/xaml 页面位于 view/student/ 因为 About 页面正在工作,而 Student 页面不想

超链接按钮的代码:

<HyperlinkButton x:Name="Link2" Style="{StaticResource LinkStyle}" 
                                     NavigateUri="/About" TargetName="ContentFrame" Content="{Binding Path=Strings.AboutPageTitle, Source={StaticResource ApplicationResources}}"/>
            <Rectangle x:Name="Divider2" Style="{StaticResource DividerStyle}"/>

            <HyperlinkButton x:Name="Link3" Style="{StaticResource LinkStyle}" 
                                     NavigateUri="Views/Student" TargetName="ContentFrame" Content="{Binding Path=Strings.StudentPageTitle, Source={StaticResource ApplicationResources}}"/>

uri映射代码:

<navigation:Frame x:Name="ContentFrame" Style="{StaticResource ContentFrameStyle}" 
                              Source="/Home" Navigated="ContentFrame_Navigated" NavigationFailed="ContentFrame_NavigationFailed">
                <navigation:Frame.UriMapper>
                  <uriMapper:UriMapper>
                    <uriMapper:UriMapping Uri="" MappedUri="/Views/Home.xaml"/>
                        <uriMapper:UriMapping Uri="/{pageName}" MappedUri="/Views/{pageName}.xaml"/>
                        <uriMapper:UriMapping Uri="/Student/{pageName}" MappedUri="/Views/Student/{pageName}.xaml"/>
                    </uriMapper:UriMapper>
                </navigation:Frame.UriMapper>
            </navigation:Frame>   

private void ContentFrame_Navigated(object sender, NavigationEventArgs e)
{
    foreach (UIElement child in LinksStackPanel.Children)
    {
        HyperlinkButton hb = child as HyperlinkButton;
        if (hb != null && hb.NavigateUri != null)
        {
            if (hb.NavigateUri.ToString().Equals(e.Uri.ToString()))
            {
                VisualStateManager.GoToState(hb, "ActiveLink", true);
            }
            else
            {
                VisualStateManager.GoToState(hb, "InactiveLink", true);
            }
        }
    }
}
4

1 回答 1

0

It seems like you've forgotten a "/" in your "Link3"-Hyperlink. You should replace NavigateUri="Views/Student" with NavigateUri="/Views/Student"

BUT: All in all your UriMapping looks a bit strange to me. If you click on your About-Hyperlink it will use the mapping Uri="/{pageName}" and navigate to "/Views/About.xaml"

--> If you want to Navigate to your Students.xaml you should use NavigateUri="/Student" only which will end up navigating to "/Views/Student.xaml"

Hope that helps ;)

于 2012-06-22T08:39:05.120 回答