【问题标题】:Content for the uri cannot be loaded无法加载 uri 的内容
【发布时间】:2012-06-17 12:59:47
【问题描述】:

我尝试在 mainpage.xaml 中添加一个超链接,该超链接位于 student.xaml 页面上。 student/xaml 页面位于 view/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);
            }
        }
    }
}

【问题讨论】:

  • 你得到的是NavigateUri="Views/Student",而不是NavigateUri="/Views/Student"。我不敢说这是问题所在,但值得让事情保持一致。

标签: silverlight navigation uri


【解决方案1】:

您似乎忘记了“Link3”-超链接中的“/”。 您应该将 NavigateUri="Views/Student" 替换为 NavigateUri="/Views/Student"

但是: 总而言之,你的 UriMapping 对我来说有点奇怪。 如果您单击 About-Hyperlink,它将使用映射 Uri="/{pageName}" 并导航到“/Views/About.xaml”

--> 如果您想导航到 Students.xaml,您应该只使用 NavigateUri="/Student" 最终会导航到“/Views/Student.xaml”

希望有所帮助;)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-10-06
    • 2013-02-14
    • 1970-01-01
    • 1970-01-01
    • 2012-10-22
    • 1970-01-01
    • 1970-01-01
    • 2011-11-15
    相关资源
    最近更新 更多