0

学生.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

「Link3」ハイパーリンクの「/」を忘れたようです。NavigateUri="Views/Student" を NavigateUri="/Views/Student" に置き換える必要があります

BUT: 全体として、あなたの UriMapping は私には少し奇妙に見えます。About-Hyperlink をクリックすると、マッピング Uri="/{pageName}" が使用され、"/Views/About.xaml" に移動します。

--> Students.xaml に移動する場合は、最終的に "/Views/Student.xaml" に移動するNavigateUri="/Student"のみを使用する必要があります。

それが役立つことを願っています;)

于 2012-06-22T08:39:05.120 に答える