2012-06-17 41 views
0

我試圖在main.x.xl中添加超鏈接,該超鏈接在student.xaml頁面上。 學生/ XAML頁面位於視圖/學生/ 對於關於頁面正在和學生頁面不希望無法加載uri的內容

代碼hyperlinkbutton:

<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); 
      } 
     } 
    } 
} 
+0

你已經有了'NavigateUri =「查看/學生」 '而不是'NavigateUri =「/ Views/Student」'。我毫不猶豫地建議這是問題,但值得一致。 – ChrisF

回答

0

這似乎就像你已經在你的「Link3」-Hyperlink中忘記了一個「/」。 此時應更換NavigateUri =「查看/學生」與NavigateUri =「/查看/學生」

但是: 所有的一切你UriMapping看起來有點怪我。 如果您點擊關於超鏈接,它將使用映射Uri =「/ {pageName}」並導航到「/Views/About.xaml」

- >如果您要導航到您的Students.xaml你應該使用NavigateUri =「/學生」只有這最終將導航到「/Views/Student.xaml」

希望幫助;)